Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
ProcessBuilder.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\Process;
013
014 @trigger_error(sprintf('The %s class is deprecated since Symfony 3.4 and will be removed in 4.0. Use the Process class instead.', ProcessBuilder::class), \E_USER_DEPRECATED);
015
016 use Symfony\Component\Process\Exception\InvalidArgumentException;
017 use Symfony\Component\Process\Exception\LogicException;
018
019 /**
020 * @author Kris Wallsmith <kris@symfony.com>
021 *
022 * @deprecated since version 3.4, to be removed in 4.0. Use the Process class instead.
023 */
024 class ProcessBuilder
025 {
026 private $arguments;
027 private $cwd;
028 private $env = [];
029 private $input;
030 private $timeout = 60;
031 private $options;
032 private $inheritEnv = true;
033 private $prefix = [];
034 private $outputDisabled = false;
035
036 /**
037 * @param string[] $arguments An array of arguments
038 */
039 public function __construct(array $arguments = [])
040 {
041 $this->arguments = $arguments;
042 }
043
044 /**
045 * Creates a process builder instance.
046 *
047 * @param string[] $arguments An array of arguments
048 *
049 * @return static
050 */
051 public static function create(array $arguments = [])
052 {
053 return new static($arguments);
054 }
055
056 /**
057 * Adds an unescaped argument to the command string.
058 *
059 * @param string $argument A command argument
060 *
061 * @return $this
062 */
063 public function add($argument)
064 {
065 $this->arguments[] = $argument;
066
067 return $this;
068 }
069
070 /**
071 * Adds a prefix to the command string.
072 *
073 * The prefix is preserved when resetting arguments.
074 *
075 * @param string|array $prefix A command prefix or an array of command prefixes
076 *
077 * @return $this
078 */
079 public function setPrefix($prefix)
080 {
081 $this->prefix = \is_array($prefix) ? $prefix : [$prefix];
082
083 return $this;
084 }
085
086 /**
087 * Sets the arguments of the process.
088 *
089 * Arguments must not be escaped.
090 * Previous arguments are removed.
091 *
092 * @param string[] $arguments
093 *
094 * @return $this
095 */
096 public function setArguments(array $arguments)
097 {
098 $this->arguments = $arguments;
099
100 return $this;
101 }
102
103 /**
104 * Sets the working directory.
105 *
106 * @param string|null $cwd The working directory
107 *
108 * @return $this
109 */
110 public function setWorkingDirectory($cwd)
111 {
112 $this->cwd = $cwd;
113
114 return $this;
115 }
116
117 /**
118 * Sets whether environment variables will be inherited or not.
119 *
120 * @param bool $inheritEnv
121 *
122 * @return $this
123 */
124 public function inheritEnvironmentVariables($inheritEnv = true)
125 {
126 $this->inheritEnv = $inheritEnv;
127
128 return $this;
129 }
130
131 /**
132 * Sets an environment variable.
133 *
134 * Setting a variable overrides its previous value. Use `null` to unset a
135 * defined environment variable.
136 *
137 * @param string $name The variable name
138 * @param string|null $value The variable value
139 *
140 * @return $this
141 */
142 public function setEnv($name, $value)
143 {
144 $this->env[$name] = $value;
145
146 return $this;
147 }
148
149 /**
150 * Adds a set of environment variables.
151 *
152 * Already existing environment variables with the same name will be
153 * overridden by the new values passed to this method. Pass `null` to unset
154 * a variable.
155 *
156 * @param array $variables The variables
157 *
158 * @return $this
159 */
160 public function addEnvironmentVariables(array $variables)
161 {
162 $this->env = array_replace($this->env, $variables);
163
164 return $this;
165 }
166
167 /**
168 * Sets the input of the process.
169 *
170 * @param resource|string|int|float|bool|\Traversable|null $input The input content
171 *
172 * @return $this
173 *
174 * @throws InvalidArgumentException In case the argument is invalid
175 */
176 public function setInput($input)
177 {
178 $this->input = ProcessUtils::validateInput(__METHOD__, $input);
179
180 return $this;
181 }
182
183 /**
184 * Sets the process timeout.
185 *
186 * To disable the timeout, set this value to null.
187 *
188 * @param float|null $timeout
189 *
190 * @return $this
191 *
192 * @throws InvalidArgumentException
193 */
194 public function setTimeout($timeout)
195 {
196 if (null === $timeout) {
197 $this->timeout = null;
198
199 return $this;
200 }
201
202 $timeout = (float) $timeout;
203
204 if ($timeout < 0) {
205 throw new InvalidArgumentException('The timeout value must be a valid positive integer or float number.');
206 }
207
208 $this->timeout = $timeout;
209
210 return $this;
211 }
212
213 /**
214 * Adds a proc_open option.
215 *
216 * @param string $name The option name
217 * @param string $value The option value
218 *
219 * @return $this
220 */
221 public function setOption($name, $value)
222 {
223 $this->options[$name] = $value;
224
225 return $this;
226 }
227
228 /**
229 * Disables fetching output and error output from the underlying process.
230 *
231 * @return $this
232 */
233 public function disableOutput()
234 {
235 $this->outputDisabled = true;
236
237 return $this;
238 }
239
240 /**
241 * Enables fetching output and error output from the underlying process.
242 *
243 * @return $this
244 */
245 public function enableOutput()
246 {
247 $this->outputDisabled = false;
248
249 return $this;
250 }
251
252 /**
253 * Creates a Process instance and returns it.
254 *
255 * @return Process
256 *
257 * @throws LogicException In case no arguments have been provided
258 */
259 public function getProcess()
260 {
261 if (0 === \count($this->prefix) && 0 === \count($this->arguments)) {
262 throw new LogicException('You must add() command arguments before calling getProcess().');
263 }
264
265 $arguments = array_merge($this->prefix, $this->arguments);
266 $process = new Process($arguments, $this->cwd, $this->env, $this->input, $this->timeout, $this->options);
267 // to preserve the BC with symfony <3.3, we convert the array structure
268 // to a string structure to avoid the prefixing with the exec command
269 $process->setCommandLine($process->getCommandLine());
270
271 if ($this->inheritEnv) {
272 $process->inheritEnvironmentVariables();
273 }
274 if ($this->outputDisabled) {
275 $process->disableOutput();
276 }
277
278 return $process;
279 }
280 }
281