45 if (
'\\' === DIRECTORY_SEPARATOR) {
46 if (
'' === $argument) {
47 return escapeshellarg($argument);
50 $escapedArgument =
'';
52 foreach (preg_split(
'/(")/', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
54 $escapedArgument .=
'\\"';
55 } elseif (self::isSurroundedBy($part,
'%')) {
57 $escapedArgument .=
'^%"'.substr($part, 1, -1).
'"^%';
60 if (
'\\' === substr($part, -1)) {
64 $escapedArgument .= $part;
68 $escapedArgument =
'"'.$escapedArgument.
'"';
71 return $escapedArgument;
74 return escapeshellarg($argument);
89 if (null !== $input) {
90 if (is_resource($input)) {
93 if (is_string($input)) {
96 if (is_scalar($input)) {
97 return (
string) $input;
99 if ($input instanceof
Process) {
100 return $input->getIterator($input::ITER_SKIP_ERR);
106 return new \IteratorIterator($input);
109 throw new InvalidArgumentException(sprintf(
'%s only accepts strings, Traversable objects or stream resources.', $caller));
117 return 2 < strlen($arg) && $char === $arg[0] && $char === $arg[strlen($arg) - 1];
static isSurroundedBy($arg, $char)
static validateInput($caller, $input)
Validates and normalizes a Process input.
ProcessUtils is a bunch of utility methods.
static escapeArgument($argument)
Escapes a string to be used as a shell argument.
Process is a thin wrapper around proc_* functions to easily start independent PHP processes...
__construct()
This class should not be instantiated.