1 | <?php |
||
17 | class 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 | * Constructor. |
||
30 | * |
||
31 | * @param string[] $arguments An array of arguments |
||
32 | */ |
||
33 | public function __construct(array $arguments = array()) |
||
37 | /** |
||
38 | * Creates a process builder instance. |
||
39 | * |
||
40 | * @param string[] $arguments An array of arguments |
||
41 | * |
||
42 | * @return static |
||
43 | */ |
||
44 | public static function create(array $arguments = array()) |
||
48 | /** |
||
49 | * Adds an unescaped argument to the command string. |
||
50 | * |
||
51 | * @param string $argument A command argument |
||
52 | * |
||
53 | * @return $this |
||
54 | */ |
||
55 | public function add($argument) |
||
60 | /** |
||
61 | * Adds a prefix to the command string. |
||
62 | * |
||
63 | * The prefix is preserved when resetting arguments. |
||
64 | * |
||
65 | * @param string|array $prefix A command prefix or an array of command prefixes |
||
66 | * |
||
67 | * @return $this |
||
68 | */ |
||
69 | public function setPrefix($prefix) |
||
74 | /** |
||
75 | * Sets the arguments of the process. |
||
76 | * |
||
77 | * Arguments must not be escaped. |
||
78 | * Previous arguments are removed. |
||
79 | * |
||
80 | * @param string[] $arguments |
||
81 | * |
||
82 | * @return $this |
||
83 | */ |
||
84 | public function setArguments(array $arguments) |
||
89 | /** |
||
90 | * Sets the working directory. |
||
91 | * |
||
92 | * @param null|string $cwd The working directory |
||
93 | * |
||
94 | * @return $this |
||
95 | */ |
||
96 | public function setWorkingDirectory($cwd) |
||
101 | /** |
||
102 | * Sets whether environment variables will be inherited or not. |
||
103 | * |
||
104 | * @param bool $inheritEnv |
||
105 | * |
||
106 | * @return $this |
||
107 | */ |
||
108 | public function inheritEnvironmentVariables($inheritEnv = true) |
||
113 | /** |
||
114 | * Sets an environment variable. |
||
115 | * |
||
116 | * Setting a variable overrides its previous value. Use `null` to unset a |
||
117 | * defined environment variable. |
||
118 | * |
||
119 | * @param string $name The variable name |
||
120 | * @param null|string $value The variable value |
||
121 | * |
||
122 | * @return $this |
||
123 | */ |
||
124 | public function setEnv($name, $value) |
||
129 | /** |
||
130 | * Adds a set of environment variables. |
||
131 | * |
||
132 | * Already existing environment variables with the same name will be |
||
133 | * overridden by the new values passed to this method. Pass `null` to unset |
||
134 | * a variable. |
||
135 | * |
||
136 | * @param array $variables The variables |
||
137 | * |
||
138 | * @return $this |
||
139 | */ |
||
140 | public function addEnvironmentVariables(array $variables) |
||
145 | /** |
||
146 | * Sets the input of the process. |
||
147 | * |
||
148 | * @param resource|scalar|\Traversable|null $input The input content |
||
149 | * |
||
150 | * @return $this |
||
151 | * |
||
152 | * @throws InvalidArgumentException In case the argument is invalid |
||
153 | */ |
||
154 | public function setInput($input) |
||
159 | /** |
||
160 | * Sets the process timeout. |
||
161 | * |
||
162 | * To disable the timeout, set this value to null. |
||
163 | * |
||
164 | * @param float|null $timeout |
||
165 | * |
||
166 | * @return $this |
||
167 | * |
||
168 | * @throws InvalidArgumentException |
||
169 | */ |
||
170 | public function setTimeout($timeout) |
||
183 | /** |
||
184 | * Adds a proc_open option. |
||
185 | * |
||
186 | * @param string $name The option name |
||
187 | * @param string $value The option value |
||
188 | * |
||
189 | * @return $this |
||
190 | */ |
||
191 | public function setOption($name, $value) |
||
196 | /** |
||
197 | * Disables fetching output and error output from the underlying process. |
||
198 | * |
||
199 | * @return $this |
||
200 | */ |
||
201 | public function disableOutput() |
||
206 | /** |
||
207 | * Enables fetching output and error output from the underlying process. |
||
208 | * |
||
209 | * @return $this |
||
210 | */ |
||
211 | public function enableOutput() |
||
216 | /** |
||
217 | * Creates a Process instance and returns it. |
||
218 | * |
||
219 | * @return Process |
||
220 | * |
||
221 | * @throws LogicException In case no arguments have been provided |
||
222 | */ |
||
223 | public function getProcess() |
||
244 | } |
||
245 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.