Skip to content

Commit 4ffe85f

Browse files
committed
feat: add new methods for get str as array
1 parent c165362 commit 4ffe85f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/FlagsParser.php

+27
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Toolkit\Stdlib\Obj;
1212
use Toolkit\Stdlib\Obj\Traits\NameAliasTrait;
1313
use Toolkit\Stdlib\Obj\Traits\QuickInitTrait;
14+
use Toolkit\Stdlib\Str;
1415
use function array_merge;
1516
use function array_shift;
1617
use function array_values;
@@ -375,6 +376,32 @@ public function __toString(): string
375376
*/
376377
abstract public function buildHelp(bool $withColor = true): string;
377378

379+
/**
380+
* @param string $name
381+
* @param string $sep
382+
*
383+
* @return string[]
384+
*/
385+
public function getOptStrAsArray(string $name, string $sep = ','): array
386+
{
387+
$str = $this->getOpt($name);
388+
389+
return $str ? Str::toNoEmptyArray($str, $sep) : [];
390+
}
391+
392+
/**
393+
* @param string $name
394+
* @param string $sep
395+
*
396+
* @return int[]
397+
*/
398+
public function getOptStrAsInts(string $name, string $sep = ','): array
399+
{
400+
$str = $this->getOpt($name);
401+
402+
return $str ? Str::toInts($str, $sep) : [];
403+
}
404+
378405
/****************************************************************
379406
* getter/setter methods
380407
***************************************************************/

0 commit comments

Comments
 (0)