PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.2
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.2
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / vendor / symfony / process / Pipes / UnixPipes.php

UnixPipes.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.2, at vendor/symfony/process/Pipes/UnixPipes.php

149 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 ?bool $ttyMode;
26 private bool $ptyMode;
27 private bool $haveReadSupport;
28
29 public function __construct(?bool $ttyMode, bool $ptyMode, mixed $input, bool $haveReadSupport)
30 {
31 $this->ttyMode = $ttyMode;
32 $this->ptyMode = $ptyMode;
33 $this->haveReadSupport = $haveReadSupport;
34
35 parent::__construct($input);
36 }
37
38 public function __serialize(): array
39 {
40 throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
41 }
42
43 public function __unserialize(array $data): void
44 {
45 throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
46 }
47
48 public function __destruct()
49 {
50 $this->close();
51 }
52
53 public function getDescriptors(): array
54 {
55 if (!$this->haveReadSupport) {
56 $nullstream = fopen('/dev/null', 'c');
57
58 return [
59 ['pipe', 'r'],
60 $nullstream,
61 $nullstream,
62 ];
63 }
64
65 if ($this->ttyMode) {
66 return [
67 ['file', '/dev/tty', 'r'],
68 ['file', '/dev/tty', 'w'],
69 ['file', '/dev/tty', 'w'],
70 ];
71 }
72
73 if ($this->ptyMode && Process::isPtySupported()) {
74 return [
75 ['pty'],
76 ['pty'],
77 ['pipe', 'w'], // stderr needs to be in a pipe to correctly split error and output, since PHP will use the same stream for both
78 ];
79 }
80
81 return [
82 ['pipe', 'r'],
83 ['pipe', 'w'], // stdout
84 ['pipe', 'w'], // stderr
85 ];
86 }
87
88 public function getFiles(): array
89 {
90 return [];
91 }
92
93 public function readAndWrite(bool $blocking, bool $close = false): array
94 {
95 $this->unblock();
96 $w = $this->write();
97
98 $read = $e = [];
99 $r = $this->pipes;
100 unset($r[0]);
101
102 // let's have a look if something changed in streams
103 set_error_handler($this->handleError(...));
104 if (($r || $w) && false === stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
105 restore_error_handler();
106 // if a system call has been interrupted, forget about it, let's try again
107 // otherwise, an error occurred, let's reset pipes
108 if (!$this->hasSystemCallBeenInterrupted()) {
109 $this->pipes = [];
110 }
111
112 return $read;
113 }
114 restore_error_handler();
115
116 foreach ($r as $pipe) {
117 // prior PHP 5.4 the array passed to stream_select is modified and
118 // lose key association, we have to find back the key
119 $read[$type = array_search($pipe, $this->pipes, true)] = '';
120
121 do {
122 $data = @fread($pipe, self::CHUNK_SIZE);
123 $read[$type] .= $data;
124 } while (isset($data[0]) && ($close || isset($data[self::CHUNK_SIZE - 1])));
125
126 if (!isset($read[$type][0])) {
127 unset($read[$type]);
128 }
129
130 if ($close && feof($pipe)) {
131 fclose($pipe);
132 unset($this->pipes[$type]);
133 }
134 }
135
136 return $read;
137 }
138
139 public function haveReadSupport(): bool
140 {
141 return $this->haveReadSupport;
142 }
143
144 public function areOpen(): bool
145 {
146 return (bool) $this->pipes;
147 }
148 }
149