PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 3.1.0
Defender Security – Malware Scanner, Login Security & Firewall v3.1.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / symfony / process / Pipes / UnixPipes.php

UnixPipes.php in Defender Security – Malware Scanner, Login Security & Firewall 3.1.0, at vendor/symfony/process/Pipes/UnixPipes.php

167 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Process\Pipes;
13
14 use Symfony\Component\Process\Process;
15
16 /**
17 * UnixPipes implementation uses unix pipes as handles.
18 *
19 * @author Romain Neutron <[email protected]>
20 *
21 * @internal
22 */
23 class UnixPipes extends AbstractPipes
24 {
25 private $ttyMode;
26 private $ptyMode;
27 private $haveReadSupport;
28
29 public function __construct(?bool $ttyMode, bool $ptyMode, $input, bool $haveReadSupport)
30 {
31 $this->ttyMode = $ttyMode;
32 $this->ptyMode = $ptyMode;
33 $this->haveReadSupport = $haveReadSupport;
34
35 parent::__construct($input);
36 }
37
38 /**
39 * @return array
40 */
41 public function __sleep()
42 {
43 throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
44 }
45
46 public function __wakeup()
47 {
48 throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
49 }
50
51 public function __destruct()
52 {
53 $this->close();
54 }
55
56 /**
57 * {@inheritdoc}
58 */
59 public function getDescriptors(): array
60 {
61 if (!$this->haveReadSupport) {
62 $nullstream = fopen('/dev/null', 'c');
63
64 return [
65 ['pipe', 'r'],
66 $nullstream,
67 $nullstream,
68 ];
69 }
70
71 if ($this->ttyMode) {
72 return [
73 ['file', '/dev/tty', 'r'],
74 ['file', '/dev/tty', 'w'],
75 ['file', '/dev/tty', 'w'],
76 ];
77 }
78
79 if ($this->ptyMode && Process::isPtySupported()) {
80 return [
81 ['pty'],
82 ['pty'],
83 ['pty'],
84 ];
85 }
86
87 return [
88 ['pipe', 'r'],
89 ['pipe', 'w'], // stdout
90 ['pipe', 'w'], // stderr
91 ];
92 }
93
94 /**
95 * {@inheritdoc}
96 */
97 public function getFiles(): array
98 {
99 return [];
100 }
101
102 /**
103 * {@inheritdoc}
104 */
105 public function readAndWrite(bool $blocking, bool $close = false): array
106 {
107 $this->unblock();
108 $w = $this->write();
109
110 $read = $e = [];
111 $r = $this->pipes;
112 unset($r[0]);
113
114 // let's have a look if something changed in streams
115 set_error_handler([$this, 'handleError']);
116 if (($r || $w) && false === stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
117 restore_error_handler();
118 // if a system call has been interrupted, forget about it, let's try again
119 // otherwise, an error occurred, let's reset pipes
120 if (!$this->hasSystemCallBeenInterrupted()) {
121 $this->pipes = [];
122 }
123
124 return $read;
125 }
126 restore_error_handler();
127
128 foreach ($r as $pipe) {
129 // prior PHP 5.4 the array passed to stream_select is modified and
130 // lose key association, we have to find back the key
131 $read[$type = array_search($pipe, $this->pipes, true)] = '';
132
133 do {
134 $data = @fread($pipe, self::CHUNK_SIZE);
135 $read[$type] .= $data;
136 } while (isset($data[0]) && ($close || isset($data[self::CHUNK_SIZE - 1])));
137
138 if (!isset($read[$type][0])) {
139 unset($read[$type]);
140 }
141
142 if ($close && feof($pipe)) {
143 fclose($pipe);
144 unset($this->pipes[$type]);
145 }
146 }
147
148 return $read;
149 }
150
151 /**
152 * {@inheritdoc}
153 */
154 public function haveReadSupport(): bool
155 {
156 return $this->haveReadSupport;
157 }
158
159 /**
160 * {@inheritdoc}
161 */
162 public function areOpen(): bool
163 {
164 return (bool) $this->pipes;
165 }
166 }
167