PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / symfony / process / Pipes / UnixPipes.php
matomo / app / vendor / symfony / process / Pipes Last commit date
AbstractPipes.php 1 year ago PipesInterface.php 1 year ago UnixPipes.php 1 year ago WindowsPipes.php 1 year ago
UnixPipes.php
129 lines
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace Symfony\Component\Process\Pipes;
12
13 use Symfony\Component\Process\Process;
14 /**
15 * UnixPipes implementation uses unix pipes as handles.
16 *
17 * @author Romain Neutron <imprec@gmail.com>
18 *
19 * @internal
20 */
21 class UnixPipes extends \Symfony\Component\Process\Pipes\AbstractPipes
22 {
23 private $ttyMode;
24 private $ptyMode;
25 private $haveReadSupport;
26 public function __construct(?bool $ttyMode, bool $ptyMode, $input, bool $haveReadSupport)
27 {
28 $this->ttyMode = $ttyMode;
29 $this->ptyMode = $ptyMode;
30 $this->haveReadSupport = $haveReadSupport;
31 parent::__construct($input);
32 }
33 public function __sleep() : array
34 {
35 throw new \BadMethodCallException('Cannot serialize ' . __CLASS__);
36 }
37 public function __wakeup()
38 {
39 throw new \BadMethodCallException('Cannot unserialize ' . __CLASS__);
40 }
41 public function __destruct()
42 {
43 $this->close();
44 }
45 /**
46 * {@inheritdoc}
47 */
48 public function getDescriptors() : array
49 {
50 if (!$this->haveReadSupport) {
51 $nullstream = fopen('/dev/null', 'c');
52 return [['pipe', 'r'], $nullstream, $nullstream];
53 }
54 if ($this->ttyMode) {
55 return [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']];
56 }
57 if ($this->ptyMode && Process::isPtySupported()) {
58 return [['pty'], ['pty'], ['pty']];
59 }
60 return [
61 ['pipe', 'r'],
62 ['pipe', 'w'],
63 // stdout
64 ['pipe', 'w'],
65 ];
66 }
67 /**
68 * {@inheritdoc}
69 */
70 public function getFiles() : array
71 {
72 return [];
73 }
74 /**
75 * {@inheritdoc}
76 */
77 public function readAndWrite(bool $blocking, bool $close = \false) : array
78 {
79 $this->unblock();
80 $w = $this->write();
81 $read = $e = [];
82 $r = $this->pipes;
83 unset($r[0]);
84 // let's have a look if something changed in streams
85 set_error_handler([$this, 'handleError']);
86 if (($r || $w) && \false === stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1000000.0 : 0)) {
87 restore_error_handler();
88 // if a system call has been interrupted, forget about it, let's try again
89 // otherwise, an error occurred, let's reset pipes
90 if (!$this->hasSystemCallBeenInterrupted()) {
91 $this->pipes = [];
92 }
93 return $read;
94 }
95 restore_error_handler();
96 foreach ($r as $pipe) {
97 // prior PHP 5.4 the array passed to stream_select is modified and
98 // lose key association, we have to find back the key
99 $read[$type = array_search($pipe, $this->pipes, \true)] = '';
100 do {
101 $data = @fread($pipe, self::CHUNK_SIZE);
102 $read[$type] .= $data;
103 } while (isset($data[0]) && ($close || isset($data[self::CHUNK_SIZE - 1])));
104 if (!isset($read[$type][0])) {
105 unset($read[$type]);
106 }
107 if ($close && feof($pipe)) {
108 fclose($pipe);
109 unset($this->pipes[$type]);
110 }
111 }
112 return $read;
113 }
114 /**
115 * {@inheritdoc}
116 */
117 public function haveReadSupport() : bool
118 {
119 return $this->haveReadSupport;
120 }
121 /**
122 * {@inheritdoc}
123 */
124 public function areOpen() : bool
125 {
126 return (bool) $this->pipes;
127 }
128 }
129