Skip to content

Commit aa7b587

Browse files
committed
up: add new string util method Str.shellQuotes()
1 parent 02b2fca commit aa7b587

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Str/StringHelper.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use DateTime;
1313
use Exception;
14+
use JetBrains\PhpStorm\Pure;
1415
use Stringable;
1516
use Toolkit\Stdlib\Str\Traits\StringCaseHelperTrait;
1617
use Toolkit\Stdlib\Str\Traits\StringCheckHelperTrait;
@@ -418,6 +419,22 @@ public static function wrap(mixed $str, string $wrapChar): string
418419
return $wrapChar . $str . $wrapChar;
419420
}
420421

422+
/**
423+
* @param string[]|array $args
424+
*
425+
* @return string[]
426+
*/
427+
public static function shellQuotes(array $args): array
428+
{
429+
$newArgs = [];
430+
foreach ($args as $arg) {
431+
$newArgs[] = self::shellQuote((string)$arg);
432+
}
433+
434+
// return implode(' ', $newArgs);
435+
return $newArgs;
436+
}
437+
421438
/**
422439
* @param string $arg
423440
*

0 commit comments

Comments
 (0)