Add pear modules, mail and net_smtp via composer (#93)
Add pear modules, mail and net_smtp via composer, remove php 5.6 build due to phpunit 6
This commit is contained in:
307
lib/composer/vendor/symfony/process/Process.php
vendored
307
lib/composer/vendor/symfony/process/Process.php
vendored
@@ -58,7 +58,7 @@ class Process implements \IteratorAggregate
|
||||
private $lastOutputTime;
|
||||
private $timeout;
|
||||
private $idleTimeout;
|
||||
private $options;
|
||||
private $options = array('suppress_errors' => true);
|
||||
private $exitcode;
|
||||
private $fallbackStatus = array();
|
||||
private $processInformation;
|
||||
@@ -73,6 +73,7 @@ class Process implements \IteratorAggregate
|
||||
private $incrementalErrorOutputOffset = 0;
|
||||
private $tty;
|
||||
private $pty;
|
||||
private $inheritEnv = false;
|
||||
|
||||
private $useFileHandles = false;
|
||||
/** @var PipesInterface */
|
||||
@@ -86,8 +87,6 @@ class Process implements \IteratorAggregate
|
||||
* Exit codes translation table.
|
||||
*
|
||||
* User-defined errors must use exit codes in the 64-113 range.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $exitCodes = array(
|
||||
0 => 'OK',
|
||||
@@ -133,9 +132,7 @@ class Process implements \IteratorAggregate
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $commandline The command line to run
|
||||
* @param string|array $commandline The command line to run
|
||||
* @param string|null $cwd The working directory or null to use the working dir of the current PHP process
|
||||
* @param array|null $env The environment variables or null to use the same environment as the current PHP process
|
||||
* @param mixed|null $input The input as stream resource, scalar or \Traversable, or null for no input
|
||||
@@ -144,7 +141,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @throws RuntimeException When proc_open is not installed
|
||||
*/
|
||||
public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array())
|
||||
public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = null)
|
||||
{
|
||||
if (!function_exists('proc_open')) {
|
||||
throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
|
||||
@@ -168,9 +165,11 @@ class Process implements \IteratorAggregate
|
||||
$this->setTimeout($timeout);
|
||||
$this->useFileHandles = '\\' === DIRECTORY_SEPARATOR;
|
||||
$this->pty = false;
|
||||
$this->enhanceWindowsCompatibility = true;
|
||||
$this->enhanceSigchildCompatibility = '\\' !== DIRECTORY_SEPARATOR && $this->isSigchildEnabled();
|
||||
$this->options = array_replace(array('suppress_errors' => true, 'binary_pipes' => true), $options);
|
||||
if (null !== $options) {
|
||||
@trigger_error(sprintf('The $options parameter of the %s constructor is deprecated since Symfony 3.3 and will be removed in 4.0.', __CLASS__), E_USER_DEPRECATED);
|
||||
$this->options = array_replace($this->options, $options);
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
@@ -195,16 +194,20 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @param callable|null $callback A PHP callback to run whenever there is some
|
||||
* output available on STDOUT or STDERR
|
||||
* @param array $env An array of additional env vars to set when running the process
|
||||
*
|
||||
* @return int The exit status code
|
||||
*
|
||||
* @throws RuntimeException When process can't be launched
|
||||
* @throws RuntimeException When process stopped after receiving signal
|
||||
* @throws LogicException In case a callback is provided and output has been disabled
|
||||
*
|
||||
* @final since version 3.3
|
||||
*/
|
||||
public function run($callback = null)
|
||||
public function run($callback = null/*, array $env = array()*/)
|
||||
{
|
||||
$this->start($callback);
|
||||
$env = 1 < func_num_args() ? func_get_arg(1) : null;
|
||||
$this->start($callback, $env);
|
||||
|
||||
return $this->wait();
|
||||
}
|
||||
@@ -216,19 +219,23 @@ class Process implements \IteratorAggregate
|
||||
* exits with a non-zero exit code.
|
||||
*
|
||||
* @param callable|null $callback
|
||||
* @param array $env An array of additional env vars to set when running the process
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
* @throws RuntimeException if PHP was compiled with --enable-sigchild and the enhanced sigchild compatibility mode is not enabled
|
||||
* @throws ProcessFailedException if the process didn't terminate successfully
|
||||
*
|
||||
* @final since version 3.3
|
||||
*/
|
||||
public function mustRun(callable $callback = null)
|
||||
public function mustRun(callable $callback = null/*, array $env = array()*/)
|
||||
{
|
||||
if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
|
||||
throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
|
||||
}
|
||||
$env = 1 < func_num_args() ? func_get_arg(1) : null;
|
||||
|
||||
if (0 !== $this->run($callback)) {
|
||||
if (0 !== $this->run($callback, $env)) {
|
||||
throw new ProcessFailedException($this);
|
||||
}
|
||||
|
||||
@@ -249,49 +256,90 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @param callable|null $callback A PHP callback to run whenever there is some
|
||||
* output available on STDOUT or STDERR
|
||||
* @param array $env An array of additional env vars to set when running the process
|
||||
*
|
||||
* @throws RuntimeException When process can't be launched
|
||||
* @throws RuntimeException When process is already running
|
||||
* @throws LogicException In case a callback is provided and output has been disabled
|
||||
*/
|
||||
public function start(callable $callback = null)
|
||||
public function start(callable $callback = null/*, array $env = array()*/)
|
||||
{
|
||||
if ($this->isRunning()) {
|
||||
throw new RuntimeException('Process is already running');
|
||||
}
|
||||
if (2 <= func_num_args()) {
|
||||
$env = func_get_arg(1);
|
||||
} else {
|
||||
if (__CLASS__ !== static::class) {
|
||||
$r = new \ReflectionMethod($this, __FUNCTION__);
|
||||
if (__CLASS__ !== $r->getDeclaringClass()->getName() && (2 > $r->getNumberOfParameters() || 'env' !== $r->getParameters()[0]->name)) {
|
||||
@trigger_error(sprintf('The %s::start() method expects a second "$env" argument since Symfony 3.3. It will be made mandatory in 4.0.', static::class), E_USER_DEPRECATED);
|
||||
}
|
||||
}
|
||||
$env = null;
|
||||
}
|
||||
|
||||
$this->resetProcessData();
|
||||
$this->starttime = $this->lastOutputTime = microtime(true);
|
||||
$this->callback = $this->buildCallback($callback);
|
||||
$this->hasCallback = null !== $callback;
|
||||
$descriptors = $this->getDescriptors();
|
||||
$inheritEnv = $this->inheritEnv;
|
||||
|
||||
$commandline = $this->commandline;
|
||||
if (is_array($commandline = $this->commandline)) {
|
||||
$commandline = implode(' ', array_map(array($this, 'escapeArgument'), $commandline));
|
||||
|
||||
if ('\\' !== DIRECTORY_SEPARATOR) {
|
||||
// exec is mandatory to deal with sending a signal to the process
|
||||
$commandline = 'exec '.$commandline;
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $env) {
|
||||
$env = $this->env;
|
||||
} else {
|
||||
if ($this->env) {
|
||||
$env += $this->env;
|
||||
}
|
||||
$inheritEnv = true;
|
||||
}
|
||||
|
||||
if (null !== $env && $inheritEnv) {
|
||||
$env += $this->getDefaultEnv();
|
||||
} elseif (null !== $env) {
|
||||
@trigger_error('Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead.', E_USER_DEPRECATED);
|
||||
} else {
|
||||
$env = $this->getDefaultEnv();
|
||||
}
|
||||
if ('\\' === DIRECTORY_SEPARATOR && $this->enhanceWindowsCompatibility) {
|
||||
$commandline = 'cmd /V:ON /E:ON /D /C "('.$commandline.')';
|
||||
foreach ($this->processPipes->getFiles() as $offset => $filename) {
|
||||
$commandline .= ' '.$offset.'>'.ProcessUtils::escapeArgument($filename);
|
||||
}
|
||||
$commandline .= '"';
|
||||
|
||||
if (!isset($this->options['bypass_shell'])) {
|
||||
$this->options['bypass_shell'] = true;
|
||||
}
|
||||
$this->options['bypass_shell'] = true;
|
||||
$commandline = $this->prepareWindowsCommandLine($commandline, $env);
|
||||
} elseif (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
|
||||
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild
|
||||
$descriptors[3] = array('pipe', 'w');
|
||||
|
||||
// See https://unix.stackexchange.com/questions/71205/background-process-pipe-input
|
||||
$commandline = '{ ('.$this->commandline.') <&3 3<&- 3>/dev/null & } 3<&0;';
|
||||
$commandline = '{ ('.$commandline.') <&3 3<&- 3>/dev/null & } 3<&0;';
|
||||
$commandline .= 'pid=$!; echo $pid >&3; wait $pid; code=$?; echo $code >&3; exit $code';
|
||||
|
||||
// Workaround for the bug, when PTS functionality is enabled.
|
||||
// @see : https://bugs.php.net/69442
|
||||
$ptsWorkaround = fopen(__FILE__, 'r');
|
||||
}
|
||||
if (defined('HHVM_VERSION')) {
|
||||
$envPairs = $env;
|
||||
} else {
|
||||
$envPairs = array();
|
||||
foreach ($env as $k => $v) {
|
||||
$envPairs[] = $k.'='.$v;
|
||||
}
|
||||
}
|
||||
|
||||
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $this->env, $this->options);
|
||||
if (!is_dir($this->cwd)) {
|
||||
@trigger_error('The provided cwd does not exist. Command is currently ran against getcwd(). This behavior is deprecated since Symfony 3.4 and will be removed in 4.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options);
|
||||
|
||||
if (!is_resource($this->process)) {
|
||||
throw new RuntimeException('Unable to launch a new process.');
|
||||
@@ -317,22 +365,26 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @param callable|null $callback A PHP callback to run whenever there is some
|
||||
* output available on STDOUT or STDERR
|
||||
* @param array $env An array of additional env vars to set when running the process
|
||||
*
|
||||
* @return Process The new process
|
||||
* @return $this
|
||||
*
|
||||
* @throws RuntimeException When process can't be launched
|
||||
* @throws RuntimeException When process is already running
|
||||
*
|
||||
* @see start()
|
||||
*
|
||||
* @final since version 3.3
|
||||
*/
|
||||
public function restart(callable $callback = null)
|
||||
public function restart(callable $callback = null/*, array $env = array()*/)
|
||||
{
|
||||
if ($this->isRunning()) {
|
||||
throw new RuntimeException('Process is already running');
|
||||
}
|
||||
$env = 1 < func_num_args() ? func_get_arg(1) : null;
|
||||
|
||||
$process = clone $this;
|
||||
$process->start($callback);
|
||||
$process->start($callback, $env);
|
||||
|
||||
return $process;
|
||||
}
|
||||
@@ -361,7 +413,7 @@ class Process implements \IteratorAggregate
|
||||
if (null !== $callback) {
|
||||
if (!$this->processPipes->haveReadSupport()) {
|
||||
$this->stop(0);
|
||||
throw new \LogicException('Pass the callback to the Process:start method or enableOutput to use a callback with Process::wait');
|
||||
throw new \LogicException('Pass the callback to the Process::start method or enableOutput to use a callback with Process::wait');
|
||||
}
|
||||
$this->callback = $this->buildCallback($callback);
|
||||
}
|
||||
@@ -398,7 +450,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @param int $signal A valid POSIX signal (see http://www.php.net/manual/en/pcntl.constants.php)
|
||||
*
|
||||
* @return Process
|
||||
* @return $this
|
||||
*
|
||||
* @throws LogicException In case the process is not running
|
||||
* @throws RuntimeException In case --enable-sigchild is activated and the process can't be killed
|
||||
@@ -414,7 +466,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Disables fetching output and error output from the underlying process.
|
||||
*
|
||||
* @return Process
|
||||
* @return $this
|
||||
*
|
||||
* @throws RuntimeException In case the process is already running
|
||||
* @throws LogicException if an idle timeout is set
|
||||
@@ -436,7 +488,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Enables fetching output and error output from the underlying process.
|
||||
*
|
||||
* @return Process
|
||||
* @return $this
|
||||
*
|
||||
* @throws RuntimeException In case the process is already running
|
||||
*/
|
||||
@@ -557,6 +609,7 @@ class Process implements \IteratorAggregate
|
||||
yield self::OUT => '';
|
||||
}
|
||||
|
||||
$this->checkTimeout();
|
||||
$this->readPipesForOutput(__FUNCTION__, $blocking);
|
||||
}
|
||||
}
|
||||
@@ -564,7 +617,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Clears the process output.
|
||||
*
|
||||
* @return Process
|
||||
* @return $this
|
||||
*/
|
||||
public function clearOutput()
|
||||
{
|
||||
@@ -623,7 +676,7 @@ class Process implements \IteratorAggregate
|
||||
/**
|
||||
* Clears the process output.
|
||||
*
|
||||
* @return Process
|
||||
* @return $this
|
||||
*/
|
||||
public function clearErrorOutput()
|
||||
{
|
||||
@@ -779,7 +832,7 @@ class Process implements \IteratorAggregate
|
||||
*/
|
||||
public function isStarted()
|
||||
{
|
||||
return $this->status != self::STATUS_READY;
|
||||
return self::STATUS_READY != $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -791,7 +844,7 @@ class Process implements \IteratorAggregate
|
||||
{
|
||||
$this->updateStatus(false);
|
||||
|
||||
return $this->status == self::STATUS_TERMINATED;
|
||||
return self::STATUS_TERMINATED == $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -884,13 +937,13 @@ class Process implements \IteratorAggregate
|
||||
*/
|
||||
public function getCommandLine()
|
||||
{
|
||||
return $this->commandline;
|
||||
return is_array($this->commandline) ? implode(' ', array_map(array($this, 'escapeArgument'), $this->commandline)) : $this->commandline;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the command line to be executed.
|
||||
*
|
||||
* @param string $commandline The command to execute
|
||||
* @param string|array $commandline The command to execute
|
||||
*
|
||||
* @return self The current Process instance
|
||||
*/
|
||||
@@ -976,8 +1029,16 @@ class Process implements \IteratorAggregate
|
||||
if ('\\' === DIRECTORY_SEPARATOR && $tty) {
|
||||
throw new RuntimeException('TTY mode is not supported on Windows platform.');
|
||||
}
|
||||
if ($tty && (!file_exists('/dev/tty') || !is_readable('/dev/tty'))) {
|
||||
throw new RuntimeException('TTY mode requires /dev/tty to be readable.');
|
||||
if ($tty) {
|
||||
static $isTtySupported;
|
||||
|
||||
if (null === $isTtySupported) {
|
||||
$isTtySupported = (bool) @proc_open('echo 1 >/dev/null', array(array('file', '/dev/tty', 'r'), array('file', '/dev/tty', 'w'), array('file', '/dev/tty', 'w')), $pipes);
|
||||
}
|
||||
|
||||
if (!$isTtySupported) {
|
||||
throw new RuntimeException('TTY mode requires /dev/tty to be read/writable.');
|
||||
}
|
||||
}
|
||||
|
||||
$this->tty = (bool) $tty;
|
||||
@@ -1064,6 +1125,8 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* An environment variable value should be a string.
|
||||
* If it is an array, the variable is ignored.
|
||||
* If it is false or null, it will be removed when
|
||||
* env vars are otherwise inherited.
|
||||
*
|
||||
* That happens in PHP when 'argv' is registered into
|
||||
* the $_ENV array for instance.
|
||||
@@ -1079,10 +1142,7 @@ class Process implements \IteratorAggregate
|
||||
return !is_array($value);
|
||||
});
|
||||
|
||||
$this->env = array();
|
||||
foreach ($env as $key => $value) {
|
||||
$this->env[$key] = (string) $value;
|
||||
}
|
||||
$this->env = $env;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -1123,9 +1183,13 @@ class Process implements \IteratorAggregate
|
||||
* Gets the options for proc_open.
|
||||
*
|
||||
* @return array The current options
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
@@ -1135,9 +1199,13 @@ class Process implements \IteratorAggregate
|
||||
* @param array $options The new options
|
||||
*
|
||||
* @return self The current Process instance
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
$this->options = $options;
|
||||
|
||||
return $this;
|
||||
@@ -1149,9 +1217,13 @@ class Process implements \IteratorAggregate
|
||||
* This is true by default.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Enhanced Windows compatibility will always be enabled.
|
||||
*/
|
||||
public function getEnhanceWindowsCompatibility()
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Enhanced Windows compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
return $this->enhanceWindowsCompatibility;
|
||||
}
|
||||
|
||||
@@ -1161,9 +1233,13 @@ class Process implements \IteratorAggregate
|
||||
* @param bool $enhance
|
||||
*
|
||||
* @return self The current Process instance
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Enhanced Windows compatibility will always be enabled.
|
||||
*/
|
||||
public function setEnhanceWindowsCompatibility($enhance)
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Enhanced Windows compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
$this->enhanceWindowsCompatibility = (bool) $enhance;
|
||||
|
||||
return $this;
|
||||
@@ -1173,9 +1249,13 @@ class Process implements \IteratorAggregate
|
||||
* Returns whether sigchild compatibility mode is activated or not.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Sigchild compatibility will always be enabled.
|
||||
*/
|
||||
public function getEnhanceSigchildCompatibility()
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Sigchild compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
return $this->enhanceSigchildCompatibility;
|
||||
}
|
||||
|
||||
@@ -1189,14 +1269,50 @@ class Process implements \IteratorAggregate
|
||||
* @param bool $enhance
|
||||
*
|
||||
* @return self The current Process instance
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function setEnhanceSigchildCompatibility($enhance)
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Sigchild compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
$this->enhanceSigchildCompatibility = (bool) $enhance;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether environment variables will be inherited or not.
|
||||
*
|
||||
* @param bool $inheritEnv
|
||||
*
|
||||
* @return self The current Process instance
|
||||
*/
|
||||
public function inheritEnvironmentVariables($inheritEnv = true)
|
||||
{
|
||||
if (!$inheritEnv) {
|
||||
@trigger_error('Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->inheritEnv = (bool) $inheritEnv;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether environment variables will be inherited or not.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0. Environment variables will always be inherited.
|
||||
*/
|
||||
public function areEnvironmentVariablesInherited()
|
||||
{
|
||||
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Environment variables will always be inherited.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
return $this->inheritEnv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a check between the timeout definition and the time the process started.
|
||||
*
|
||||
@@ -1207,7 +1323,7 @@ class Process implements \IteratorAggregate
|
||||
*/
|
||||
public function checkTimeout()
|
||||
{
|
||||
if ($this->status !== self::STATUS_STARTED) {
|
||||
if (self::STATUS_STARTED !== $this->status) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1241,7 +1357,7 @@ class Process implements \IteratorAggregate
|
||||
return $result = false;
|
||||
}
|
||||
|
||||
return $result = (bool) @proc_open('echo 1', array(array('pty'), array('pty'), array('pty')), $pipes);
|
||||
return $result = (bool) @proc_open('echo 1 >/dev/null', array(array('pty'), array('pty'), array('pty')), $pipes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1398,7 +1514,7 @@ class Process implements \IteratorAggregate
|
||||
$callback = $this->callback;
|
||||
foreach ($result as $type => $data) {
|
||||
if (3 !== $type) {
|
||||
$callback($type === self::STDOUT ? self::OUT : self::ERR, $data);
|
||||
$callback(self::STDOUT === $type ? self::OUT : self::ERR, $data);
|
||||
} elseif (!isset($this->fallbackStatus['signaled'])) {
|
||||
$this->fallbackStatus['exitcode'] = (int) $data;
|
||||
}
|
||||
@@ -1512,12 +1628,58 @@ class Process implements \IteratorAggregate
|
||||
return true;
|
||||
}
|
||||
|
||||
private function prepareWindowsCommandLine($cmd, array &$env)
|
||||
{
|
||||
$uid = uniqid('', true);
|
||||
$varCount = 0;
|
||||
$varCache = array();
|
||||
$cmd = preg_replace_callback(
|
||||
'/"(?:(
|
||||
[^"%!^]*+
|
||||
(?:
|
||||
(?: !LF! | "(?:\^[%!^])?+" )
|
||||
[^"%!^]*+
|
||||
)++
|
||||
) | [^"]*+ )"/x',
|
||||
function ($m) use (&$env, &$varCache, &$varCount, $uid) {
|
||||
if (!isset($m[1])) {
|
||||
return $m[0];
|
||||
}
|
||||
if (isset($varCache[$m[0]])) {
|
||||
return $varCache[$m[0]];
|
||||
}
|
||||
if (false !== strpos($value = $m[1], "\0")) {
|
||||
$value = str_replace("\0", '?', $value);
|
||||
}
|
||||
if (false === strpbrk($value, "\"%!\n")) {
|
||||
return '"'.$value.'"';
|
||||
}
|
||||
|
||||
$value = str_replace(array('!LF!', '"^!"', '"^%"', '"^^"', '""'), array("\n", '!', '%', '^', '"'), $value);
|
||||
$value = '"'.preg_replace('/(\\\\*)"/', '$1$1\\"', $value).'"';
|
||||
$var = $uid.++$varCount;
|
||||
|
||||
$env[$var] = $value;
|
||||
|
||||
return $varCache[$m[0]] = '!'.$var.'!';
|
||||
},
|
||||
$cmd
|
||||
);
|
||||
|
||||
$cmd = 'cmd /V:ON /E:ON /D /C ('.str_replace("\n", ' ', $cmd).')';
|
||||
foreach ($this->processPipes->getFiles() as $offset => $filename) {
|
||||
$cmd .= ' '.$offset.'>"'.$filename.'"';
|
||||
}
|
||||
|
||||
return $cmd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the process is running or terminated, throws a LogicException if the process has a not started.
|
||||
*
|
||||
* @param string $functionName The function name that was called
|
||||
*
|
||||
* @throws LogicException If the process has not run.
|
||||
* @throws LogicException if the process has not run
|
||||
*/
|
||||
private function requireProcessIsStarted($functionName)
|
||||
{
|
||||
@@ -1531,7 +1693,7 @@ class Process implements \IteratorAggregate
|
||||
*
|
||||
* @param string $functionName The function name that was called
|
||||
*
|
||||
* @throws LogicException If the process is not yet terminated.
|
||||
* @throws LogicException if the process is not yet terminated
|
||||
*/
|
||||
private function requireProcessIsTerminated($functionName)
|
||||
{
|
||||
@@ -1539,4 +1701,49 @@ class Process implements \IteratorAggregate
|
||||
throw new LogicException(sprintf('Process must be terminated before calling %s.', $functionName));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a string to be used as a shell argument.
|
||||
*
|
||||
* @param string $argument The argument that will be escaped
|
||||
*
|
||||
* @return string The escaped argument
|
||||
*/
|
||||
private function escapeArgument($argument)
|
||||
{
|
||||
if ('\\' !== DIRECTORY_SEPARATOR) {
|
||||
return "'".str_replace("'", "'\\''", $argument)."'";
|
||||
}
|
||||
if ('' === $argument = (string) $argument) {
|
||||
return '""';
|
||||
}
|
||||
if (false !== strpos($argument, "\0")) {
|
||||
$argument = str_replace("\0", '?', $argument);
|
||||
}
|
||||
if (!preg_match('/[\/()%!^"<>&|\s]/', $argument)) {
|
||||
return $argument;
|
||||
}
|
||||
$argument = preg_replace('/(\\\\+)$/', '$1$1', $argument);
|
||||
|
||||
return '"'.str_replace(array('"', '^', '%', '!', "\n"), array('""', '"^^"', '"^%"', '"^!"', '!LF!'), $argument).'"';
|
||||
}
|
||||
|
||||
private function getDefaultEnv()
|
||||
{
|
||||
$env = array();
|
||||
|
||||
foreach ($_SERVER as $k => $v) {
|
||||
if (is_string($v) && false !== $v = getenv($k)) {
|
||||
$env[$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($_ENV as $k => $v) {
|
||||
if (is_string($v)) {
|
||||
$env[$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
return $env;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user