X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fsymfony%2Fprocess%2FPipes%2FAbstractPipes.php;h=9a7d88be896f45fde753bfdd03ddab3e202c65e3;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=1a94755bd71c1c74d6481acb087abb60f18fc20a;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/vendor/symfony/process/Pipes/AbstractPipes.php b/vendor/symfony/process/Pipes/AbstractPipes.php index 1a94755bd..9a7d88be8 100644 --- a/vendor/symfony/process/Pipes/AbstractPipes.php +++ b/vendor/symfony/process/Pipes/AbstractPipes.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Process\Pipes; +use Symfony\Component\Process\Exception\InvalidArgumentException; + /** * @author Romain Neutron * @@ -18,19 +20,19 @@ namespace Symfony\Component\Process\Pipes; */ abstract class AbstractPipes implements PipesInterface { - /** @var array */ public $pipes = array(); - /** @var string */ private $inputBuffer = ''; - /** @var resource|null */ private $input; - /** @var bool */ private $blocked = true; + private $lastError; + /** + * @param resource|string|int|float|bool|\Iterator|null $input + */ public function __construct($input) { - if (is_resource($input)) { + if (is_resource($input) || $input instanceof \Iterator) { $this->input = $input; } elseif (is_string($input)) { $this->inputBuffer = $input; @@ -57,10 +59,11 @@ abstract class AbstractPipes implements PipesInterface */ protected function hasSystemCallBeenInterrupted() { - $lastError = error_get_last(); + $lastError = $this->lastError; + $this->lastError = null; // stream_select returns false when the `select` system call is interrupted by an incoming signal - return isset($lastError['message']) && false !== stripos($lastError['message'], 'interrupted system call'); + return null !== $lastError && false !== stripos($lastError, 'interrupted system call'); } /** @@ -75,7 +78,7 @@ abstract class AbstractPipes implements PipesInterface foreach ($this->pipes as $pipe) { stream_set_blocking($pipe, 0); } - if (null !== $this->input) { + if (is_resource($this->input)) { stream_set_blocking($this->input, 0); } @@ -84,6 +87,8 @@ abstract class AbstractPipes implements PipesInterface /** * Writes input to stdin. + * + * @throws InvalidArgumentException When an input iterator yields a non supported value */ protected function write() { @@ -91,11 +96,32 @@ abstract class AbstractPipes implements PipesInterface return; } $input = $this->input; + + if ($input instanceof \Iterator) { + if (!$input->valid()) { + $input = null; + } elseif (is_resource($input = $input->current())) { + stream_set_blocking($input, 0); + } elseif (!isset($this->inputBuffer[0])) { + if (!is_string($input)) { + if (!is_scalar($input)) { + throw new InvalidArgumentException(sprintf('%s yielded a value of type "%s", but only scalars and stream resources are supported', get_class($this->input), gettype($input))); + } + $input = (string) $input; + } + $this->inputBuffer = $input; + $this->input->next(); + $input = null; + } else { + $input = null; + } + } + $r = $e = array(); $w = array($this->pipes[0]); // let's have a look if something changed in streams - if (false === $n = @stream_select($r, $w, $e, 0, 0)) { + if (false === @stream_select($r, $w, $e, 0, 0)) { return; } @@ -123,19 +149,30 @@ abstract class AbstractPipes implements PipesInterface } } if (feof($input)) { - // no more data to read on input resource - // use an empty buffer in the next reads - $this->input = null; + if ($this->input instanceof \Iterator) { + $this->input->next(); + } else { + $this->input = null; + } } } } // no input to read on resource, buffer is empty - if (null === $this->input && !isset($this->inputBuffer[0])) { + if (!isset($this->inputBuffer[0]) && !($this->input instanceof \Iterator ? $this->input->valid() : $this->input)) { + $this->input = null; fclose($this->pipes[0]); unset($this->pipes[0]); } elseif (!$w) { return array($this->pipes[0]); } } + + /** + * @internal + */ + public function handleError($type, $msg) + { + $this->lastError = $msg; + } }