class UnixPipes
UnixPipes implementation uses unix pipes as handles.
@author Romain Neutron <imprec@gmail.com>
@internal
Hierarchy
- class \Symfony\Component\Process\Pipes\AbstractPipes implements \Symfony\Component\Process\Pipes\PipesInterface
- class \Symfony\Component\Process\Pipes\UnixPipes extends \Symfony\Component\Process\Pipes\AbstractPipes
Expanded class hierarchy of UnixPipes
1 file declares its use of UnixPipes
- Process.php in vendor/
symfony/ process/ Process.php
File
-
vendor/
symfony/ process/ Pipes/ UnixPipes.php, line 23
Namespace
Symfony\Component\Process\PipesView source
class UnixPipes extends AbstractPipes {
public function __construct(?bool $ttyMode, bool $ptyMode, mixed $input, bool $haveReadSupport) {
parent::__construct($input);
}
public function __sleep() : array {
throw new \BadMethodCallException('Cannot serialize ' . __CLASS__);
}
public function __wakeup() : void {
throw new \BadMethodCallException('Cannot unserialize ' . __CLASS__);
}
public function __destruct() {
$this->close();
}
public function getDescriptors() : array {
if (!$this->haveReadSupport) {
$nullstream = fopen('/dev/null', 'c');
return [
[
'pipe',
'r',
],
$nullstream,
$nullstream,
];
}
if ($this->ttyMode) {
return [
[
'file',
'/dev/tty',
'r',
],
[
'file',
'/dev/tty',
'w',
],
[
'file',
'/dev/tty',
'w',
],
];
}
if ($this->ptyMode && Process::isPtySupported()) {
return [
[
'pty',
],
[
'pty',
],
[
'pty',
],
];
}
return [
[
'pipe',
'r',
],
[
'pipe',
'w',
],
// stdout
[
'pipe',
'w',
],
];
}
public function getFiles() : array {
return [];
}
public function readAndWrite(bool $blocking, bool $close = false) : array {
$this->unblock();
$w = $this->write();
$read = $e = [];
$r = $this->pipes;
unset($r[0]);
// let's have a look if something changed in streams
set_error_handler($this->handleError(...));
if (($r || $w) && false === stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1000000.0 : 0)) {
restore_error_handler();
// if a system call has been interrupted, forget about it, let's try again
// otherwise, an error occurred, let's reset pipes
if (!$this->hasSystemCallBeenInterrupted()) {
$this->pipes = [];
}
return $read;
}
restore_error_handler();
foreach ($r as $pipe) {
// prior PHP 5.4 the array passed to stream_select is modified and
// lose key association, we have to find back the key
$read[$type = array_search($pipe, $this->pipes, true)] = '';
do {
$data = @fread($pipe, self::CHUNK_SIZE);
$read[$type] .= $data;
} while (isset($data[0]) && ($close || isset($data[self::CHUNK_SIZE - 1])));
if (!isset($read[$type][0])) {
unset($read[$type]);
}
if ($close && feof($pipe)) {
fclose($pipe);
unset($this->pipes[$type]);
}
}
return $read;
}
public function haveReadSupport() : bool {
return $this->haveReadSupport;
}
public function areOpen() : bool {
return (bool) $this->pipes;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
AbstractPipes::$blocked | private | property | |||
AbstractPipes::$input | private | property | @var resource|string|\Iterator | ||
AbstractPipes::$inputBuffer | private | property | |||
AbstractPipes::$lastError | private | property | |||
AbstractPipes::$pipes | public | property | |||
AbstractPipes::close | public | function | Closes file handles and pipes. | Overrides PipesInterface::close | 1 |
AbstractPipes::handleError | public | function | @internal | ||
AbstractPipes::hasSystemCallBeenInterrupted | protected | function | Returns true if a system call has been interrupted. | ||
AbstractPipes::unblock | protected | function | Unblocks streams. | ||
AbstractPipes::write | protected | function | Writes input to stdin. | ||
PipesInterface::CHUNK_SIZE | public | constant | |||
UnixPipes::areOpen | public | function | Returns if the current state has open file handles or pipes. | Overrides PipesInterface::areOpen | |
UnixPipes::getDescriptors | public | function | Returns an array of descriptors for the use of proc_open. | Overrides PipesInterface::getDescriptors | |
UnixPipes::getFiles | public | function | Returns an array of filenames indexed by their related stream in case these pipes use temporary files. | Overrides PipesInterface::getFiles | |
UnixPipes::haveReadSupport | public | function | Returns if pipes are able to read output. | Overrides PipesInterface::haveReadSupport | |
UnixPipes::readAndWrite | public | function | Reads data in file handles and pipes. | Overrides PipesInterface::readAndWrite | |
UnixPipes::__construct | public | function | Overrides AbstractPipes::__construct | ||
UnixPipes::__destruct | public | function | |||
UnixPipes::__sleep | public | function | |||
UnixPipes::__wakeup | public | function |