PluginProbe
ManageWP Worker / 4.9.25
ManageWP Worker v4.9.25
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / Symfony / Process / ProcessBuilder.php

ProcessBuilder.php in ManageWP Worker 4.9.25, at src/Symfony/Process/ProcessBuilder.php

281 lines 6.7 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 <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
12 /**
13 * Process builder.
14 *
15 * @author Kris Wallsmith <kris@symfony.com>
16 */
17 class Symfony_Process_ProcessBuilder
18 {
19 private $arguments;
20 private $cwd;
21 private $env = array();
22 private $input;
23 private $timeout = 60;
24 private $options = array();
25 private $inheritEnv = true;
26 private $prefix = array();
27 private $outputDisabled = false;
28
29 /**
30 * Constructor.
31 *
32 * @param string[] $arguments An array of arguments
33 */
34 public function __construct(array $arguments = array())
35 {
36 $this->arguments = $arguments;
37 }
38
39 /**
40 * Creates a process builder instance.
41 *
42 * @param string[] $arguments An array of arguments
43 *
44 * @return Symfony_Process_ProcessBuilder
45 */
46 public static function create(array $arguments = array())
47 {
48 return new self($arguments);
49 }
50
51 /**
52 * Adds an unescaped argument to the command string.
53 *
54 * @param string $argument A command argument
55 *
56 * @return Symfony_Process_ProcessBuilder
57 */
58 public function add($argument)
59 {
60 $this->arguments[] = $argument;
61
62 return $this;
63 }
64
65 /**
66 * Adds a prefix to the command string.
67 *
68 * The prefix is preserved when resetting arguments.
69 *
70 * @param string|array $prefix A command prefix or an array of command prefixes
71 *
72 * @return Symfony_Process_ProcessBuilder
73 */
74 public function setPrefix($prefix)
75 {
76 $this->prefix = is_array($prefix) ? $prefix : array($prefix);
77
78 return $this;
79 }
80
81 /**
82 * Sets the arguments of the process.
83 *
84 * Arguments must not be escaped.
85 * Previous arguments are removed.
86 *
87 * @param string[] $arguments
88 *
89 * @return Symfony_Process_ProcessBuilder
90 */
91 public function setArguments(array $arguments)
92 {
93 $this->arguments = $arguments;
94
95 return $this;
96 }
97
98 /**
99 * Sets the working directory.
100 *
101 * @param null|string $cwd The working directory
102 *
103 * @return Symfony_Process_ProcessBuilder
104 */
105 public function setWorkingDirectory($cwd)
106 {
107 $this->cwd = $cwd;
108
109 return $this;
110 }
111
112 /**
113 * Sets whether environment variables will be inherited or not.
114 *
115 * @param bool $inheritEnv
116 *
117 * @return Symfony_Process_ProcessBuilder
118 */
119 public function inheritEnvironmentVariables($inheritEnv = true)
120 {
121 $this->inheritEnv = $inheritEnv;
122
123 return $this;
124 }
125
126 /**
127 * Sets an environment variable.
128 *
129 * Setting a variable overrides its previous value. Use `null` to unset a
130 * defined environment variable.
131 *
132 * @param string $name The variable name
133 * @param null|string $value The variable value
134 *
135 * @return Symfony_Process_ProcessBuilder
136 */
137 public function setEnv($name, $value)
138 {
139 $this->env[$name] = $value;
140
141 return $this;
142 }
143
144 /**
145 * Adds a set of environment variables.
146 *
147 * Already existing environment variables with the same name will be
148 * overridden by the new values passed to this method. Pass `null` to unset
149 * a variable.
150 *
151 * @param array $variables The variables
152 *
153 * @return Symfony_Process_ProcessBuilder
154 */
155 public function addEnvironmentVariables(array $variables)
156 {
157 $this->env = Symfony_Process_ProcessUtils::arrayReplace($this->env, $variables);
158
159 return $this;
160 }
161
162 /**
163 * Sets the input of the process.
164 *
165 * @param mixed $input The input as a string
166 *
167 * @return Symfony_Process_ProcessBuilder
168 *
169 * @throws InvalidArgumentException In case the argument is invalid
170 */
171 public function setInput($input)
172 {
173 $this->input = Symfony_Process_ProcessUtils::validateInput(sprintf('%s::%s', __CLASS__, __FUNCTION__), $input);
174
175 return $this;
176 }
177
178 /**
179 * Sets the process timeout.
180 *
181 * To disable the timeout, set this value to null.
182 *
183 * @param float|null $timeout
184 *
185 * @return Symfony_Process_ProcessBuilder
186 *
187 * @throws InvalidArgumentException
188 */
189 public function setTimeout($timeout)
190 {
191 if (null === $timeout) {
192 $this->timeout = null;
193
194 return $this;
195 }
196
197 $timeout = (float) $timeout;
198
199 if ($timeout < 0) {
200 throw new Symfony_Process_Exception_InvalidArgumentException('The timeout value must be a valid positive integer or float number.');
201 }
202
203 $this->timeout = $timeout;
204
205 return $this;
206 }
207
208 /**
209 * Adds a proc_open option.
210 *
211 * @param string $name The option name
212 * @param string $value The option value
213 *
214 * @return Symfony_Process_ProcessBuilder
215 */
216 public function setOption($name, $value)
217 {
218 $this->options[$name] = $value;
219
220 return $this;
221 }
222
223 /**
224 * Disables fetching output and error output from the underlying process.
225 *
226 * @return Symfony_Process_ProcessBuilder
227 */
228 public function disableOutput()
229 {
230 $this->outputDisabled = true;
231
232 return $this;
233 }
234
235 /**
236 * Enables fetching output and error output from the underlying process.
237 *
238 * @return Symfony_Process_ProcessBuilder
239 */
240 public function enableOutput()
241 {
242 $this->outputDisabled = false;
243
244 return $this;
245 }
246
247 /**
248 * Creates a Process instance and returns it.
249 *
250 * @return Symfony_Process_Process
251 *
252 * @throws LogicException In case no arguments have been provided
253 */
254 public function getProcess()
255 {
256 if (0 === count($this->prefix) && 0 === count($this->arguments)) {
257 throw new Symfony_Process_Exception_LogicException('You must add() command arguments before calling getProcess().');
258 }
259
260 $options = $this->options;
261
262 $arguments = array_merge($this->prefix, $this->arguments);
263 $script = implode(' ', array_map(array('Symfony_Process_ProcessUtils', 'escapeArgument'), $arguments));
264
265 if ($this->inheritEnv) {
266 // include $_ENV for BC purposes
267 $env = Symfony_Process_ProcessUtils::arrayReplace($_ENV, $_SERVER, $this->env);
268 } else {
269 $env = $this->env;
270 }
271
272 $process = new Symfony_Process_Process($script, $this->cwd, $env, $this->input, $this->timeout, $options);
273
274 if ($this->outputDisabled) {
275 $process->disableOutput();
276 }
277
278 return $process;
279 }
280 }
281