Exceptions
2 weeks ago
Facades
2 weeks ago
Testing
2 weeks ago
Traits
2 weeks ago
AggregateServiceProvider.php
2 years ago
Benchmark.php
2 weeks ago
Carbon.php
2 weeks ago
Composer.php
2 weeks ago
ConfigurationUrlParser.php
2 weeks ago
DateFactory.php
2 weeks ago
Env.php
2 weeks ago
Fluent.php
2 weeks ago
HigherOrderTapProxy.php
2 years ago
HtmlString.php
2 years ago
InteractsWithTime.php
2 years ago
Js.php
2 weeks ago
Lottery.php
2 weeks ago
Manager.php
2 years ago
MessageBag.php
2 weeks ago
MultipleInstanceManager.php
2 weeks ago
NamespacedItemResolver.php
2 weeks ago
Optional.php
2 weeks ago
Pluralizer.php
2 weeks ago
ProcessUtils.php
2 weeks ago
Reflector.php
2 weeks ago
ServiceProvider.php
2 years ago
Str.php
2 weeks ago
Stringable.php
2 weeks ago
Timebox.php
2 weeks ago
ValidatedInput.php
2 weeks ago
ViewErrorBag.php
2 weeks ago
helpers.php
2 weeks ago
ProcessUtils.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWPSCOPED\Illuminate\Support; |
| 4 | |
| 5 | /** |
| 6 | * ProcessUtils is a bunch of utility methods. |
| 7 | * |
| 8 | * This class was originally copied from Symfony 3. |
| 9 | * @internal |
| 10 | */ |
| 11 | class ProcessUtils |
| 12 | { |
| 13 | /** |
| 14 | * Escapes a string to be used as a shell argument. |
| 15 | * |
| 16 | * @param string $argument |
| 17 | * @return string |
| 18 | */ |
| 19 | public static function escapeArgument($argument) |
| 20 | { |
| 21 | // Fix for PHP bug #43784 escapeshellarg removes % from given string |
| 22 | // Fix for PHP bug #49446 escapeshellarg doesn't work on Windows |
| 23 | // @see https://bugs.php.net/bug.php?id=43784 |
| 24 | // @see https://bugs.php.net/bug.php?id=49446 |
| 25 | if ('\\' === \DIRECTORY_SEPARATOR) { |
| 26 | if ($argument === '') { |
| 27 | return '""'; |
| 28 | } |
| 29 | $escapedArgument = ''; |
| 30 | $quote = \false; |
| 31 | foreach (\preg_split('/(")/', $argument, -1, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE) as $part) { |
| 32 | if ($part === '"') { |
| 33 | $escapedArgument .= '\\"'; |
| 34 | } elseif (self::isSurroundedBy($part, '%')) { |
| 35 | // Avoid environment variable expansion |
| 36 | $escapedArgument .= '^%"' . \substr($part, 1, -1) . '"^%'; |
| 37 | } else { |
| 38 | // escape trailing backslash |
| 39 | if (\str_ends_with($part, '\\')) { |
| 40 | $part .= '\\'; |
| 41 | } |
| 42 | $quote = \true; |
| 43 | $escapedArgument .= $part; |
| 44 | } |
| 45 | } |
| 46 | if ($quote) { |
| 47 | $escapedArgument = '"' . $escapedArgument . '"'; |
| 48 | } |
| 49 | return $escapedArgument; |
| 50 | } |
| 51 | return "'" . \str_replace("'", "'\\''", $argument) . "'"; |
| 52 | } |
| 53 | /** |
| 54 | * Is the given string surrounded by the given character? |
| 55 | * |
| 56 | * @param string $arg |
| 57 | * @param string $char |
| 58 | * @return bool |
| 59 | */ |
| 60 | protected static function isSurroundedBy($arg, $char) |
| 61 | { |
| 62 | return \strlen($arg) > 2 && $char === $arg[0] && $char === $arg[\strlen($arg) - 1]; |
| 63 | } |
| 64 | } |
| 65 |