@@ -31,13 +31,13 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @return string|false The PHP executable path or false if it cannot be found |
33 | 33 | */ |
34 | - public function find(bool $includeArgs = true) |
|
34 | + public function find( bool $includeArgs = true ) |
|
35 | 35 | { |
36 | - if ($php = getenv('PHP_BINARY')) { |
|
37 | - if (!is_executable($php)) { |
|
36 | + if ( $php = getenv( 'PHP_BINARY' ) ) { |
|
37 | + if ( ! is_executable( $php ) ) { |
|
38 | 38 | $command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v'; |
39 | - if ($php = strtok(exec($command.' '.escapeshellarg($php)), \PHP_EOL)) { |
|
40 | - if (!is_executable($php)) { |
|
39 | + if ( $php = strtok( exec( $command . ' ' . escapeshellarg( $php ) ), \PHP_EOL ) ) { |
|
40 | + if ( ! is_executable( $php ) ) { |
|
41 | 41 | return false; |
42 | 42 | } |
43 | 43 | } else { |
@@ -49,37 +49,37 @@ discard block |
||
49 | 49 | } |
50 | 50 | |
51 | 51 | $args = $this->findArguments(); |
52 | - $args = $includeArgs && $args ? ' '.implode(' ', $args) : ''; |
|
52 | + $args = $includeArgs && $args ? ' ' . implode( ' ', $args ) : ''; |
|
53 | 53 | |
54 | 54 | // PHP_BINARY return the current sapi executable |
55 | - if (\PHP_BINARY && \in_array(\PHP_SAPI, ['cgi-fcgi', 'cli', 'cli-server', 'phpdbg'], true)) { |
|
56 | - return \PHP_BINARY.$args; |
|
55 | + if ( \PHP_BINARY && \in_array( \PHP_SAPI, [ 'cgi-fcgi', 'cli', 'cli-server', 'phpdbg' ], true ) ) { |
|
56 | + return \PHP_BINARY . $args; |
|
57 | 57 | } |
58 | 58 | |
59 | - if ($php = getenv('PHP_PATH')) { |
|
60 | - if (!@is_executable($php)) { |
|
59 | + if ( $php = getenv( 'PHP_PATH' ) ) { |
|
60 | + if ( ! @is_executable( $php ) ) { |
|
61 | 61 | return false; |
62 | 62 | } |
63 | 63 | |
64 | 64 | return $php; |
65 | 65 | } |
66 | 66 | |
67 | - if ($php = getenv('PHP_PEAR_PHP_BIN')) { |
|
68 | - if (@is_executable($php)) { |
|
67 | + if ( $php = getenv( 'PHP_PEAR_PHP_BIN' ) ) { |
|
68 | + if ( @is_executable( $php ) ) { |
|
69 | 69 | return $php; |
70 | 70 | } |
71 | 71 | } |
72 | 72 | |
73 | - if (@is_executable($php = \PHP_BINDIR.('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php'))) { |
|
73 | + if ( @is_executable( $php = \PHP_BINDIR . ( '\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php' ) ) ) { |
|
74 | 74 | return $php; |
75 | 75 | } |
76 | 76 | |
77 | - $dirs = [\PHP_BINDIR]; |
|
78 | - if ('\\' === \DIRECTORY_SEPARATOR) { |
|
79 | - $dirs[] = 'C:\xampp\php\\'; |
|
77 | + $dirs = [ \PHP_BINDIR ]; |
|
78 | + if ( '\\' === \DIRECTORY_SEPARATOR ) { |
|
79 | + $dirs[ ] = 'C:\xampp\php\\'; |
|
80 | 80 | } |
81 | 81 | |
82 | - return $this->executableFinder->find('php', false, $dirs); |
|
82 | + return $this->executableFinder->find( 'php', false, $dirs ); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function findArguments() |
91 | 91 | { |
92 | - $arguments = []; |
|
93 | - if ('phpdbg' === \PHP_SAPI) { |
|
94 | - $arguments[] = '-qrr'; |
|
92 | + $arguments = [ ]; |
|
93 | + if ( 'phpdbg' === \PHP_SAPI ) { |
|
94 | + $arguments[ ] = '-qrr'; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | return $arguments; |
@@ -19,12 +19,12 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class ExecutableFinder |
21 | 21 | { |
22 | - private $suffixes = ['.exe', '.bat', '.cmd', '.com']; |
|
22 | + private $suffixes = [ '.exe', '.bat', '.cmd', '.com' ]; |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Replaces default suffixes of executable. |
26 | 26 | */ |
27 | - public function setSuffixes(array $suffixes) |
|
27 | + public function setSuffixes( array $suffixes ) |
|
28 | 28 | { |
29 | 29 | $this->suffixes = $suffixes; |
30 | 30 | } |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * Adds new possible suffix to check for executable. |
34 | 34 | */ |
35 | - public function addSuffix(string $suffix) |
|
35 | + public function addSuffix( string $suffix ) |
|
36 | 36 | { |
37 | - $this->suffixes[] = $suffix; |
|
37 | + $this->suffixes[ ] = $suffix; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -46,36 +46,36 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return string|null The executable path or default value |
48 | 48 | */ |
49 | - public function find(string $name, string $default = null, array $extraDirs = []) |
|
49 | + public function find( string $name, string $default = null, array $extraDirs = [ ] ) |
|
50 | 50 | { |
51 | - if (ini_get('open_basedir')) { |
|
52 | - $searchPath = array_merge(explode(\PATH_SEPARATOR, ini_get('open_basedir')), $extraDirs); |
|
53 | - $dirs = []; |
|
54 | - foreach ($searchPath as $path) { |
|
51 | + if ( ini_get( 'open_basedir' ) ) { |
|
52 | + $searchPath = array_merge( explode( \PATH_SEPARATOR, ini_get( 'open_basedir' ) ), $extraDirs ); |
|
53 | + $dirs = [ ]; |
|
54 | + foreach ( $searchPath as $path ) { |
|
55 | 55 | // Silencing against https://bugs.php.net/69240 |
56 | - if (@is_dir($path)) { |
|
57 | - $dirs[] = $path; |
|
56 | + if ( @is_dir( $path ) ) { |
|
57 | + $dirs[ ] = $path; |
|
58 | 58 | } else { |
59 | - if (basename($path) == $name && @is_executable($path)) { |
|
59 | + if ( basename( $path ) == $name && @is_executable( $path ) ) { |
|
60 | 60 | return $path; |
61 | 61 | } |
62 | 62 | } |
63 | 63 | } |
64 | 64 | } else { |
65 | 65 | $dirs = array_merge( |
66 | - explode(\PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')), |
|
66 | + explode( \PATH_SEPARATOR, getenv( 'PATH' ) ?: getenv( 'Path' ) ), |
|
67 | 67 | $extraDirs |
68 | 68 | ); |
69 | 69 | } |
70 | 70 | |
71 | - $suffixes = ['']; |
|
72 | - if ('\\' === \DIRECTORY_SEPARATOR) { |
|
73 | - $pathExt = getenv('PATHEXT'); |
|
74 | - $suffixes = array_merge($pathExt ? explode(\PATH_SEPARATOR, $pathExt) : $this->suffixes, $suffixes); |
|
71 | + $suffixes = [ '' ]; |
|
72 | + if ( '\\' === \DIRECTORY_SEPARATOR ) { |
|
73 | + $pathExt = getenv( 'PATHEXT' ); |
|
74 | + $suffixes = array_merge( $pathExt ? explode( \PATH_SEPARATOR, $pathExt ) : $this->suffixes, $suffixes ); |
|
75 | 75 | } |
76 | - foreach ($suffixes as $suffix) { |
|
77 | - foreach ($dirs as $dir) { |
|
78 | - if (@is_file($file = $dir.\DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === \DIRECTORY_SEPARATOR || @is_executable($file))) { |
|
76 | + foreach ( $suffixes as $suffix ) { |
|
77 | + foreach ( $dirs as $dir ) { |
|
78 | + if ( @is_file( $file = $dir . \DIRECTORY_SEPARATOR . $name . $suffix ) && ( '\\' === \DIRECTORY_SEPARATOR || @is_executable( $file ) ) ) { |
|
79 | 79 | return $file; |
80 | 80 | } |
81 | 81 | } |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | public const TIMEOUT_PRECISION = 0.2; |
46 | 46 | |
47 | 47 | public const ITER_NON_BLOCKING = 1; // By default, iterating over outputs is a blocking call, use this flag to make it non-blocking |
48 | - public const ITER_KEEP_OUTPUT = 2; // By default, outputs are cleared while iterating, use this flag to keep them in memory |
|
49 | - public const ITER_SKIP_OUT = 4; // Use this flag to skip STDOUT while iterating |
|
50 | - public const ITER_SKIP_ERR = 8; // Use this flag to skip STDERR while iterating |
|
48 | + public const ITER_KEEP_OUTPUT = 2; // By default, outputs are cleared while iterating, use this flag to keep them in memory |
|
49 | + public const ITER_SKIP_OUT = 4; // Use this flag to skip STDOUT while iterating |
|
50 | + public const ITER_SKIP_ERR = 8; // Use this flag to skip STDERR while iterating |
|
51 | 51 | |
52 | 52 | private $callback; |
53 | 53 | private $hasCallback = false; |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | private $timeout; |
61 | 61 | private $idleTimeout; |
62 | 62 | private $exitcode; |
63 | - private $fallbackStatus = []; |
|
63 | + private $fallbackStatus = [ ]; |
|
64 | 64 | private $processInformation; |
65 | 65 | private $outputDisabled = false; |
66 | 66 | private $stdout; |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | private $incrementalErrorOutputOffset = 0; |
72 | 72 | private $tty = false; |
73 | 73 | private $pty; |
74 | - private $options = ['suppress_errors' => true, 'bypass_shell' => true]; |
|
74 | + private $options = [ 'suppress_errors' => true, 'bypass_shell' => true ]; |
|
75 | 75 | |
76 | 76 | private $useFileHandles = false; |
77 | 77 | /** @var PipesInterface */ |
@@ -138,10 +138,10 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @throws LogicException When proc_open is not installed |
140 | 140 | */ |
141 | - public function __construct(array $command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60) |
|
141 | + public function __construct( array $command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60 ) |
|
142 | 142 | { |
143 | - if (!\function_exists('proc_open')) { |
|
144 | - throw new LogicException('The Process class relies on proc_open, which is not available on your PHP installation.'); |
|
143 | + if ( ! \function_exists( 'proc_open' ) ) { |
|
144 | + throw new LogicException( 'The Process class relies on proc_open, which is not available on your PHP installation.' ); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | $this->commandline = $command; |
@@ -151,15 +151,15 @@ discard block |
||
151 | 151 | // on Gnu/Linux, PHP builds with --enable-maintainer-zts are also affected |
152 | 152 | // @see : https://bugs.php.net/51800 |
153 | 153 | // @see : https://bugs.php.net/50524 |
154 | - if (null === $this->cwd && (\defined('ZEND_THREAD_SAFE') || '\\' === \DIRECTORY_SEPARATOR)) { |
|
154 | + if ( null === $this->cwd && ( \defined( 'ZEND_THREAD_SAFE' ) || '\\' === \DIRECTORY_SEPARATOR ) ) { |
|
155 | 155 | $this->cwd = getcwd(); |
156 | 156 | } |
157 | - if (null !== $env) { |
|
158 | - $this->setEnv($env); |
|
157 | + if ( null !== $env ) { |
|
158 | + $this->setEnv( $env ); |
|
159 | 159 | } |
160 | 160 | |
161 | - $this->setInput($input); |
|
162 | - $this->setTimeout($timeout); |
|
161 | + $this->setInput( $input ); |
|
162 | + $this->setTimeout( $timeout ); |
|
163 | 163 | $this->useFileHandles = '\\' === \DIRECTORY_SEPARATOR; |
164 | 164 | $this->pty = false; |
165 | 165 | } |
@@ -187,9 +187,9 @@ discard block |
||
187 | 187 | * |
188 | 188 | * @throws LogicException When proc_open is not installed |
189 | 189 | */ |
190 | - public static function fromShellCommandline(string $command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60) |
|
190 | + public static function fromShellCommandline( string $command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60 ) |
|
191 | 191 | { |
192 | - $process = new static([], $cwd, $env, $input, $timeout); |
|
192 | + $process = new static( [ ], $cwd, $env, $input, $timeout ); |
|
193 | 193 | $process->commandline = $command; |
194 | 194 | |
195 | 195 | return $process; |
@@ -200,20 +200,20 @@ discard block |
||
200 | 200 | */ |
201 | 201 | public function __sleep() |
202 | 202 | { |
203 | - throw new \BadMethodCallException('Cannot serialize '.__CLASS__); |
|
203 | + throw new \BadMethodCallException( 'Cannot serialize ' . __CLASS__ ); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | public function __wakeup() |
207 | 207 | { |
208 | - throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); |
|
208 | + throw new \BadMethodCallException( 'Cannot unserialize ' . __CLASS__ ); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | public function __destruct() |
212 | 212 | { |
213 | - if ($this->options['create_new_console'] ?? false) { |
|
213 | + if ( $this->options[ 'create_new_console' ] ?? false ) { |
|
214 | 214 | $this->processPipes->close(); |
215 | 215 | } else { |
216 | - $this->stop(0); |
|
216 | + $this->stop( 0 ); |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
@@ -245,9 +245,9 @@ discard block |
||
245 | 245 | * |
246 | 246 | * @final |
247 | 247 | */ |
248 | - public function run(callable $callback = null, array $env = []): int |
|
248 | + public function run( callable $callback = null, array $env = [ ] ): int |
|
249 | 249 | { |
250 | - $this->start($callback, $env); |
|
250 | + $this->start( $callback, $env ); |
|
251 | 251 | |
252 | 252 | return $this->wait(); |
253 | 253 | } |
@@ -264,10 +264,10 @@ discard block |
||
264 | 264 | * |
265 | 265 | * @final |
266 | 266 | */ |
267 | - public function mustRun(callable $callback = null, array $env = []): self |
|
267 | + public function mustRun( callable $callback = null, array $env = [ ] ): self |
|
268 | 268 | { |
269 | - if (0 !== $this->run($callback, $env)) { |
|
270 | - throw new ProcessFailedException($this); |
|
269 | + if ( 0 !== $this->run( $callback, $env ) ) { |
|
270 | + throw new ProcessFailedException( $this ); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | return $this; |
@@ -292,77 +292,77 @@ discard block |
||
292 | 292 | * @throws RuntimeException When process is already running |
293 | 293 | * @throws LogicException In case a callback is provided and output has been disabled |
294 | 294 | */ |
295 | - public function start(callable $callback = null, array $env = []) |
|
295 | + public function start( callable $callback = null, array $env = [ ] ) |
|
296 | 296 | { |
297 | - if ($this->isRunning()) { |
|
298 | - throw new RuntimeException('Process is already running.'); |
|
297 | + if ( $this->isRunning() ) { |
|
298 | + throw new RuntimeException( 'Process is already running.' ); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | $this->resetProcessData(); |
302 | - $this->starttime = $this->lastOutputTime = microtime(true); |
|
303 | - $this->callback = $this->buildCallback($callback); |
|
302 | + $this->starttime = $this->lastOutputTime = microtime( true ); |
|
303 | + $this->callback = $this->buildCallback( $callback ); |
|
304 | 304 | $this->hasCallback = null !== $callback; |
305 | 305 | $descriptors = $this->getDescriptors(); |
306 | 306 | |
307 | - if ($this->env) { |
|
307 | + if ( $this->env ) { |
|
308 | 308 | $env += $this->env; |
309 | 309 | } |
310 | 310 | |
311 | 311 | $env += $this->getDefaultEnv(); |
312 | 312 | |
313 | - if (\is_array($commandline = $this->commandline)) { |
|
314 | - $commandline = implode(' ', array_map([$this, 'escapeArgument'], $commandline)); |
|
313 | + if ( \is_array( $commandline = $this->commandline ) ) { |
|
314 | + $commandline = implode( ' ', array_map( [ $this, 'escapeArgument' ], $commandline ) ); |
|
315 | 315 | |
316 | - if ('\\' !== \DIRECTORY_SEPARATOR) { |
|
316 | + if ( '\\' !== \DIRECTORY_SEPARATOR ) { |
|
317 | 317 | // exec is mandatory to deal with sending a signal to the process |
318 | - $commandline = 'exec '.$commandline; |
|
318 | + $commandline = 'exec ' . $commandline; |
|
319 | 319 | } |
320 | 320 | } else { |
321 | - $commandline = $this->replacePlaceholders($commandline, $env); |
|
321 | + $commandline = $this->replacePlaceholders( $commandline, $env ); |
|
322 | 322 | } |
323 | 323 | |
324 | - if ('\\' === \DIRECTORY_SEPARATOR) { |
|
325 | - $commandline = $this->prepareWindowsCommandLine($commandline, $env); |
|
326 | - } elseif (!$this->useFileHandles && $this->isSigchildEnabled()) { |
|
324 | + if ( '\\' === \DIRECTORY_SEPARATOR ) { |
|
325 | + $commandline = $this->prepareWindowsCommandLine( $commandline, $env ); |
|
326 | + } elseif ( ! $this->useFileHandles && $this->isSigchildEnabled() ) { |
|
327 | 327 | // last exit code is output on the fourth pipe and caught to work around --enable-sigchild |
328 | - $descriptors[3] = ['pipe', 'w']; |
|
328 | + $descriptors[ 3 ] = [ 'pipe', 'w' ]; |
|
329 | 329 | |
330 | 330 | // See https://unix.stackexchange.com/questions/71205/background-process-pipe-input |
331 | - $commandline = '{ ('.$commandline.') <&3 3<&- 3>/dev/null & } 3<&0;'; |
|
331 | + $commandline = '{ (' . $commandline . ') <&3 3<&- 3>/dev/null & } 3<&0;'; |
|
332 | 332 | $commandline .= 'pid=$!; echo $pid >&3; wait $pid; code=$?; echo $code >&3; exit $code'; |
333 | 333 | |
334 | 334 | // Workaround for the bug, when PTS functionality is enabled. |
335 | 335 | // @see : https://bugs.php.net/69442 |
336 | - $ptsWorkaround = fopen(__FILE__, 'r'); |
|
336 | + $ptsWorkaround = fopen( __FILE__, 'r' ); |
|
337 | 337 | } |
338 | 338 | |
339 | - $envPairs = []; |
|
340 | - foreach ($env as $k => $v) { |
|
341 | - if (false !== $v) { |
|
342 | - $envPairs[] = $k.'='.$v; |
|
339 | + $envPairs = [ ]; |
|
340 | + foreach ( $env as $k => $v ) { |
|
341 | + if ( false !== $v ) { |
|
342 | + $envPairs[ ] = $k . '=' . $v; |
|
343 | 343 | } |
344 | 344 | } |
345 | 345 | |
346 | - if (!is_dir($this->cwd)) { |
|
347 | - throw new RuntimeException(sprintf('The provided cwd "%s" does not exist.', $this->cwd)); |
|
346 | + if ( ! is_dir( $this->cwd ) ) { |
|
347 | + throw new RuntimeException( sprintf( 'The provided cwd "%s" does not exist.', $this->cwd ) ); |
|
348 | 348 | } |
349 | 349 | |
350 | - $this->process = @proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options); |
|
350 | + $this->process = @proc_open( $commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options ); |
|
351 | 351 | |
352 | - if (!\is_resource($this->process)) { |
|
353 | - throw new RuntimeException('Unable to launch a new process.'); |
|
352 | + if ( ! \is_resource( $this->process ) ) { |
|
353 | + throw new RuntimeException( 'Unable to launch a new process.' ); |
|
354 | 354 | } |
355 | 355 | $this->status = self::STATUS_STARTED; |
356 | 356 | |
357 | - if (isset($descriptors[3])) { |
|
358 | - $this->fallbackStatus['pid'] = (int) fgets($this->processPipes->pipes[3]); |
|
357 | + if ( isset( $descriptors[ 3 ] ) ) { |
|
358 | + $this->fallbackStatus[ 'pid' ] = (int)fgets( $this->processPipes->pipes[ 3 ] ); |
|
359 | 359 | } |
360 | 360 | |
361 | - if ($this->tty) { |
|
361 | + if ( $this->tty ) { |
|
362 | 362 | return; |
363 | 363 | } |
364 | 364 | |
365 | - $this->updateStatus(false); |
|
365 | + $this->updateStatus( false ); |
|
366 | 366 | $this->checkTimeout(); |
367 | 367 | } |
368 | 368 | |
@@ -383,14 +383,14 @@ discard block |
||
383 | 383 | * |
384 | 384 | * @final |
385 | 385 | */ |
386 | - public function restart(callable $callback = null, array $env = []): self |
|
386 | + public function restart( callable $callback = null, array $env = [ ] ): self |
|
387 | 387 | { |
388 | - if ($this->isRunning()) { |
|
389 | - throw new RuntimeException('Process is already running.'); |
|
388 | + if ( $this->isRunning() ) { |
|
389 | + throw new RuntimeException( 'Process is already running.' ); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | $process = clone $this; |
393 | - $process->start($callback, $env); |
|
393 | + $process->start( $callback, $env ); |
|
394 | 394 | |
395 | 395 | return $process; |
396 | 396 | } |
@@ -410,33 +410,33 @@ discard block |
||
410 | 410 | * @throws ProcessSignaledException When process stopped after receiving signal |
411 | 411 | * @throws LogicException When process is not yet started |
412 | 412 | */ |
413 | - public function wait(callable $callback = null) |
|
413 | + public function wait( callable $callback = null ) |
|
414 | 414 | { |
415 | - $this->requireProcessIsStarted(__FUNCTION__); |
|
415 | + $this->requireProcessIsStarted( __FUNCTION__ ); |
|
416 | 416 | |
417 | - $this->updateStatus(false); |
|
417 | + $this->updateStatus( false ); |
|
418 | 418 | |
419 | - if (null !== $callback) { |
|
420 | - if (!$this->processPipes->haveReadSupport()) { |
|
421 | - $this->stop(0); |
|
422 | - throw new LogicException('Pass the callback to the "Process::start" method or call enableOutput to use a callback with "Process::wait".'); |
|
419 | + if ( null !== $callback ) { |
|
420 | + if ( ! $this->processPipes->haveReadSupport() ) { |
|
421 | + $this->stop( 0 ); |
|
422 | + throw new LogicException( 'Pass the callback to the "Process::start" method or call enableOutput to use a callback with "Process::wait".' ); |
|
423 | 423 | } |
424 | - $this->callback = $this->buildCallback($callback); |
|
424 | + $this->callback = $this->buildCallback( $callback ); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | do { |
428 | 428 | $this->checkTimeout(); |
429 | 429 | $running = '\\' === \DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->areOpen(); |
430 | - $this->readPipes($running, '\\' !== \DIRECTORY_SEPARATOR || !$running); |
|
431 | - } while ($running); |
|
430 | + $this->readPipes( $running, '\\' !== \DIRECTORY_SEPARATOR || ! $running ); |
|
431 | + } while ( $running ); |
|
432 | 432 | |
433 | - while ($this->isRunning()) { |
|
433 | + while ( $this->isRunning() ) { |
|
434 | 434 | $this->checkTimeout(); |
435 | - usleep(1000); |
|
435 | + usleep( 1000 ); |
|
436 | 436 | } |
437 | 437 | |
438 | - if ($this->processInformation['signaled'] && $this->processInformation['termsig'] !== $this->latestSignal) { |
|
439 | - throw new ProcessSignaledException($this); |
|
438 | + if ( $this->processInformation[ 'signaled' ] && $this->processInformation[ 'termsig' ] !== $this->latestSignal ) { |
|
439 | + throw new ProcessSignaledException( $this ); |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | return $this->exitcode; |
@@ -453,38 +453,38 @@ discard block |
||
453 | 453 | * @throws LogicException When process is not yet started |
454 | 454 | * @throws ProcessTimedOutException In case the timeout was reached |
455 | 455 | */ |
456 | - public function waitUntil(callable $callback): bool |
|
456 | + public function waitUntil( callable $callback ): bool |
|
457 | 457 | { |
458 | - $this->requireProcessIsStarted(__FUNCTION__); |
|
459 | - $this->updateStatus(false); |
|
458 | + $this->requireProcessIsStarted( __FUNCTION__ ); |
|
459 | + $this->updateStatus( false ); |
|
460 | 460 | |
461 | - if (!$this->processPipes->haveReadSupport()) { |
|
462 | - $this->stop(0); |
|
463 | - throw new LogicException('Pass the callback to the "Process::start" method or call enableOutput to use a callback with "Process::waitUntil".'); |
|
461 | + if ( ! $this->processPipes->haveReadSupport() ) { |
|
462 | + $this->stop( 0 ); |
|
463 | + throw new LogicException( 'Pass the callback to the "Process::start" method or call enableOutput to use a callback with "Process::waitUntil".' ); |
|
464 | 464 | } |
465 | - $callback = $this->buildCallback($callback); |
|
465 | + $callback = $this->buildCallback( $callback ); |
|
466 | 466 | |
467 | 467 | $ready = false; |
468 | - while (true) { |
|
468 | + while ( true ) { |
|
469 | 469 | $this->checkTimeout(); |
470 | 470 | $running = '\\' === \DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->areOpen(); |
471 | - $output = $this->processPipes->readAndWrite($running, '\\' !== \DIRECTORY_SEPARATOR || !$running); |
|
471 | + $output = $this->processPipes->readAndWrite( $running, '\\' !== \DIRECTORY_SEPARATOR || ! $running ); |
|
472 | 472 | |
473 | - foreach ($output as $type => $data) { |
|
474 | - if (3 !== $type) { |
|
475 | - $ready = $callback(self::STDOUT === $type ? self::OUT : self::ERR, $data) || $ready; |
|
476 | - } elseif (!isset($this->fallbackStatus['signaled'])) { |
|
477 | - $this->fallbackStatus['exitcode'] = (int) $data; |
|
473 | + foreach ( $output as $type => $data ) { |
|
474 | + if ( 3 !== $type ) { |
|
475 | + $ready = $callback( self::STDOUT === $type ? self::OUT : self::ERR, $data ) || $ready; |
|
476 | + } elseif ( ! isset( $this->fallbackStatus[ 'signaled' ] ) ) { |
|
477 | + $this->fallbackStatus[ 'exitcode' ] = (int)$data; |
|
478 | 478 | } |
479 | 479 | } |
480 | - if ($ready) { |
|
480 | + if ( $ready ) { |
|
481 | 481 | return true; |
482 | 482 | } |
483 | - if (!$running) { |
|
483 | + if ( ! $running ) { |
|
484 | 484 | return false; |
485 | 485 | } |
486 | 486 | |
487 | - usleep(1000); |
|
487 | + usleep( 1000 ); |
|
488 | 488 | } |
489 | 489 | } |
490 | 490 | |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | */ |
496 | 496 | public function getPid() |
497 | 497 | { |
498 | - return $this->isRunning() ? $this->processInformation['pid'] : null; |
|
498 | + return $this->isRunning() ? $this->processInformation[ 'pid' ] : null; |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | /** |
@@ -509,9 +509,9 @@ discard block |
||
509 | 509 | * @throws RuntimeException In case --enable-sigchild is activated and the process can't be killed |
510 | 510 | * @throws RuntimeException In case of failure |
511 | 511 | */ |
512 | - public function signal(int $signal) |
|
512 | + public function signal( int $signal ) |
|
513 | 513 | { |
514 | - $this->doSignal($signal, true); |
|
514 | + $this->doSignal( $signal, true ); |
|
515 | 515 | |
516 | 516 | return $this; |
517 | 517 | } |
@@ -526,11 +526,11 @@ discard block |
||
526 | 526 | */ |
527 | 527 | public function disableOutput() |
528 | 528 | { |
529 | - if ($this->isRunning()) { |
|
530 | - throw new RuntimeException('Disabling output while the process is running is not possible.'); |
|
529 | + if ( $this->isRunning() ) { |
|
530 | + throw new RuntimeException( 'Disabling output while the process is running is not possible.' ); |
|
531 | 531 | } |
532 | - if (null !== $this->idleTimeout) { |
|
533 | - throw new LogicException('Output can not be disabled while an idle timeout is set.'); |
|
532 | + if ( null !== $this->idleTimeout ) { |
|
533 | + throw new LogicException( 'Output can not be disabled while an idle timeout is set.' ); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | $this->outputDisabled = true; |
@@ -547,8 +547,8 @@ discard block |
||
547 | 547 | */ |
548 | 548 | public function enableOutput() |
549 | 549 | { |
550 | - if ($this->isRunning()) { |
|
551 | - throw new RuntimeException('Enabling output while the process is running is not possible.'); |
|
550 | + if ( $this->isRunning() ) { |
|
551 | + throw new RuntimeException( 'Enabling output while the process is running is not possible.' ); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | $this->outputDisabled = false; |
@@ -576,9 +576,9 @@ discard block |
||
576 | 576 | */ |
577 | 577 | public function getOutput() |
578 | 578 | { |
579 | - $this->readPipesForOutput(__FUNCTION__); |
|
579 | + $this->readPipesForOutput( __FUNCTION__ ); |
|
580 | 580 | |
581 | - if (false === $ret = stream_get_contents($this->stdout, -1, 0)) { |
|
581 | + if ( false === $ret = stream_get_contents( $this->stdout, -1, 0 ) ) { |
|
582 | 582 | return ''; |
583 | 583 | } |
584 | 584 | |
@@ -598,12 +598,12 @@ discard block |
||
598 | 598 | */ |
599 | 599 | public function getIncrementalOutput() |
600 | 600 | { |
601 | - $this->readPipesForOutput(__FUNCTION__); |
|
601 | + $this->readPipesForOutput( __FUNCTION__ ); |
|
602 | 602 | |
603 | - $latest = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset); |
|
604 | - $this->incrementalOutputOffset = ftell($this->stdout); |
|
603 | + $latest = stream_get_contents( $this->stdout, -1, $this->incrementalOutputOffset ); |
|
604 | + $this->incrementalOutputOffset = ftell( $this->stdout ); |
|
605 | 605 | |
606 | - if (false === $latest) { |
|
606 | + if ( false === $latest ) { |
|
607 | 607 | return ''; |
608 | 608 | } |
609 | 609 | |
@@ -621,50 +621,50 @@ discard block |
||
621 | 621 | * @return \Generator |
622 | 622 | */ |
623 | 623 | #[\ReturnTypeWillChange] |
624 | - public function getIterator(int $flags = 0) |
|
624 | + public function getIterator( int $flags = 0 ) |
|
625 | 625 | { |
626 | - $this->readPipesForOutput(__FUNCTION__, false); |
|
626 | + $this->readPipesForOutput( __FUNCTION__, false ); |
|
627 | 627 | |
628 | - $clearOutput = !(self::ITER_KEEP_OUTPUT & $flags); |
|
629 | - $blocking = !(self::ITER_NON_BLOCKING & $flags); |
|
630 | - $yieldOut = !(self::ITER_SKIP_OUT & $flags); |
|
631 | - $yieldErr = !(self::ITER_SKIP_ERR & $flags); |
|
628 | + $clearOutput = ! ( self::ITER_KEEP_OUTPUT & $flags ); |
|
629 | + $blocking = ! ( self::ITER_NON_BLOCKING & $flags ); |
|
630 | + $yieldOut = ! ( self::ITER_SKIP_OUT & $flags ); |
|
631 | + $yieldErr = ! ( self::ITER_SKIP_ERR & $flags ); |
|
632 | 632 | |
633 | - while (null !== $this->callback || ($yieldOut && !feof($this->stdout)) || ($yieldErr && !feof($this->stderr))) { |
|
634 | - if ($yieldOut) { |
|
635 | - $out = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset); |
|
633 | + while ( null !== $this->callback || ( $yieldOut && ! feof( $this->stdout ) ) || ( $yieldErr && ! feof( $this->stderr ) ) ) { |
|
634 | + if ( $yieldOut ) { |
|
635 | + $out = stream_get_contents( $this->stdout, -1, $this->incrementalOutputOffset ); |
|
636 | 636 | |
637 | - if (isset($out[0])) { |
|
638 | - if ($clearOutput) { |
|
637 | + if ( isset( $out[ 0 ] ) ) { |
|
638 | + if ( $clearOutput ) { |
|
639 | 639 | $this->clearOutput(); |
640 | 640 | } else { |
641 | - $this->incrementalOutputOffset = ftell($this->stdout); |
|
641 | + $this->incrementalOutputOffset = ftell( $this->stdout ); |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | yield self::OUT => $out; |
645 | 645 | } |
646 | 646 | } |
647 | 647 | |
648 | - if ($yieldErr) { |
|
649 | - $err = stream_get_contents($this->stderr, -1, $this->incrementalErrorOutputOffset); |
|
648 | + if ( $yieldErr ) { |
|
649 | + $err = stream_get_contents( $this->stderr, -1, $this->incrementalErrorOutputOffset ); |
|
650 | 650 | |
651 | - if (isset($err[0])) { |
|
652 | - if ($clearOutput) { |
|
651 | + if ( isset( $err[ 0 ] ) ) { |
|
652 | + if ( $clearOutput ) { |
|
653 | 653 | $this->clearErrorOutput(); |
654 | 654 | } else { |
655 | - $this->incrementalErrorOutputOffset = ftell($this->stderr); |
|
655 | + $this->incrementalErrorOutputOffset = ftell( $this->stderr ); |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | yield self::ERR => $err; |
659 | 659 | } |
660 | 660 | } |
661 | 661 | |
662 | - if (!$blocking && !isset($out[0]) && !isset($err[0])) { |
|
662 | + if ( ! $blocking && ! isset( $out[ 0 ] ) && ! isset( $err[ 0 ] ) ) { |
|
663 | 663 | yield self::OUT => ''; |
664 | 664 | } |
665 | 665 | |
666 | 666 | $this->checkTimeout(); |
667 | - $this->readPipesForOutput(__FUNCTION__, $blocking); |
|
667 | + $this->readPipesForOutput( __FUNCTION__, $blocking ); |
|
668 | 668 | } |
669 | 669 | } |
670 | 670 | |
@@ -675,8 +675,8 @@ discard block |
||
675 | 675 | */ |
676 | 676 | public function clearOutput() |
677 | 677 | { |
678 | - ftruncate($this->stdout, 0); |
|
679 | - fseek($this->stdout, 0); |
|
678 | + ftruncate( $this->stdout, 0 ); |
|
679 | + fseek( $this->stdout, 0 ); |
|
680 | 680 | $this->incrementalOutputOffset = 0; |
681 | 681 | |
682 | 682 | return $this; |
@@ -692,9 +692,9 @@ discard block |
||
692 | 692 | */ |
693 | 693 | public function getErrorOutput() |
694 | 694 | { |
695 | - $this->readPipesForOutput(__FUNCTION__); |
|
695 | + $this->readPipesForOutput( __FUNCTION__ ); |
|
696 | 696 | |
697 | - if (false === $ret = stream_get_contents($this->stderr, -1, 0)) { |
|
697 | + if ( false === $ret = stream_get_contents( $this->stderr, -1, 0 ) ) { |
|
698 | 698 | return ''; |
699 | 699 | } |
700 | 700 | |
@@ -715,12 +715,12 @@ discard block |
||
715 | 715 | */ |
716 | 716 | public function getIncrementalErrorOutput() |
717 | 717 | { |
718 | - $this->readPipesForOutput(__FUNCTION__); |
|
718 | + $this->readPipesForOutput( __FUNCTION__ ); |
|
719 | 719 | |
720 | - $latest = stream_get_contents($this->stderr, -1, $this->incrementalErrorOutputOffset); |
|
721 | - $this->incrementalErrorOutputOffset = ftell($this->stderr); |
|
720 | + $latest = stream_get_contents( $this->stderr, -1, $this->incrementalErrorOutputOffset ); |
|
721 | + $this->incrementalErrorOutputOffset = ftell( $this->stderr ); |
|
722 | 722 | |
723 | - if (false === $latest) { |
|
723 | + if ( false === $latest ) { |
|
724 | 724 | return ''; |
725 | 725 | } |
726 | 726 | |
@@ -734,8 +734,8 @@ discard block |
||
734 | 734 | */ |
735 | 735 | public function clearErrorOutput() |
736 | 736 | { |
737 | - ftruncate($this->stderr, 0); |
|
738 | - fseek($this->stderr, 0); |
|
737 | + ftruncate( $this->stderr, 0 ); |
|
738 | + fseek( $this->stderr, 0 ); |
|
739 | 739 | $this->incrementalErrorOutputOffset = 0; |
740 | 740 | |
741 | 741 | return $this; |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | */ |
749 | 749 | public function getExitCode() |
750 | 750 | { |
751 | - $this->updateStatus(false); |
|
751 | + $this->updateStatus( false ); |
|
752 | 752 | |
753 | 753 | return $this->exitcode; |
754 | 754 | } |
@@ -766,11 +766,11 @@ discard block |
||
766 | 766 | */ |
767 | 767 | public function getExitCodeText() |
768 | 768 | { |
769 | - if (null === $exitcode = $this->getExitCode()) { |
|
769 | + if ( null === $exitcode = $this->getExitCode() ) { |
|
770 | 770 | return null; |
771 | 771 | } |
772 | 772 | |
773 | - return self::$exitCodes[$exitcode] ?? 'Unknown error'; |
|
773 | + return self::$exitCodes[ $exitcode ] ?? 'Unknown error'; |
|
774 | 774 | } |
775 | 775 | |
776 | 776 | /** |
@@ -794,9 +794,9 @@ discard block |
||
794 | 794 | */ |
795 | 795 | public function hasBeenSignaled() |
796 | 796 | { |
797 | - $this->requireProcessIsTerminated(__FUNCTION__); |
|
797 | + $this->requireProcessIsTerminated( __FUNCTION__ ); |
|
798 | 798 | |
799 | - return $this->processInformation['signaled']; |
|
799 | + return $this->processInformation[ 'signaled' ]; |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | /** |
@@ -811,13 +811,13 @@ discard block |
||
811 | 811 | */ |
812 | 812 | public function getTermSignal() |
813 | 813 | { |
814 | - $this->requireProcessIsTerminated(__FUNCTION__); |
|
814 | + $this->requireProcessIsTerminated( __FUNCTION__ ); |
|
815 | 815 | |
816 | - if ($this->isSigchildEnabled() && -1 === $this->processInformation['termsig']) { |
|
817 | - throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.'); |
|
816 | + if ( $this->isSigchildEnabled() && -1 === $this->processInformation[ 'termsig' ] ) { |
|
817 | + throw new RuntimeException( 'This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.' ); |
|
818 | 818 | } |
819 | 819 | |
820 | - return $this->processInformation['termsig']; |
|
820 | + return $this->processInformation[ 'termsig' ]; |
|
821 | 821 | } |
822 | 822 | |
823 | 823 | /** |
@@ -831,9 +831,9 @@ discard block |
||
831 | 831 | */ |
832 | 832 | public function hasBeenStopped() |
833 | 833 | { |
834 | - $this->requireProcessIsTerminated(__FUNCTION__); |
|
834 | + $this->requireProcessIsTerminated( __FUNCTION__ ); |
|
835 | 835 | |
836 | - return $this->processInformation['stopped']; |
|
836 | + return $this->processInformation[ 'stopped' ]; |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | /** |
@@ -847,9 +847,9 @@ discard block |
||
847 | 847 | */ |
848 | 848 | public function getStopSignal() |
849 | 849 | { |
850 | - $this->requireProcessIsTerminated(__FUNCTION__); |
|
850 | + $this->requireProcessIsTerminated( __FUNCTION__ ); |
|
851 | 851 | |
852 | - return $this->processInformation['stopsig']; |
|
852 | + return $this->processInformation[ 'stopsig' ]; |
|
853 | 853 | } |
854 | 854 | |
855 | 855 | /** |
@@ -859,13 +859,13 @@ discard block |
||
859 | 859 | */ |
860 | 860 | public function isRunning() |
861 | 861 | { |
862 | - if (self::STATUS_STARTED !== $this->status) { |
|
862 | + if ( self::STATUS_STARTED !== $this->status ) { |
|
863 | 863 | return false; |
864 | 864 | } |
865 | 865 | |
866 | - $this->updateStatus(false); |
|
866 | + $this->updateStatus( false ); |
|
867 | 867 | |
868 | - return $this->processInformation['running']; |
|
868 | + return $this->processInformation[ 'running' ]; |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | /** |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | */ |
886 | 886 | public function isTerminated() |
887 | 887 | { |
888 | - $this->updateStatus(false); |
|
888 | + $this->updateStatus( false ); |
|
889 | 889 | |
890 | 890 | return self::STATUS_TERMINATED == $this->status; |
891 | 891 | } |
@@ -899,7 +899,7 @@ discard block |
||
899 | 899 | */ |
900 | 900 | public function getStatus() |
901 | 901 | { |
902 | - $this->updateStatus(false); |
|
902 | + $this->updateStatus( false ); |
|
903 | 903 | |
904 | 904 | return $this->status; |
905 | 905 | } |
@@ -912,28 +912,28 @@ discard block |
||
912 | 912 | * |
913 | 913 | * @return int|null The exit-code of the process or null if it's not running |
914 | 914 | */ |
915 | - public function stop(float $timeout = 10, int $signal = null) |
|
915 | + public function stop( float $timeout = 10, int $signal = null ) |
|
916 | 916 | { |
917 | - $timeoutMicro = microtime(true) + $timeout; |
|
918 | - if ($this->isRunning()) { |
|
917 | + $timeoutMicro = microtime( true ) + $timeout; |
|
918 | + if ( $this->isRunning() ) { |
|
919 | 919 | // given SIGTERM may not be defined and that "proc_terminate" uses the constant value and not the constant itself, we use the same here |
920 | - $this->doSignal(15, false); |
|
920 | + $this->doSignal( 15, false ); |
|
921 | 921 | do { |
922 | - usleep(1000); |
|
923 | - } while ($this->isRunning() && microtime(true) < $timeoutMicro); |
|
922 | + usleep( 1000 ); |
|
923 | + } while ( $this->isRunning() && microtime( true ) < $timeoutMicro ); |
|
924 | 924 | |
925 | - if ($this->isRunning()) { |
|
925 | + if ( $this->isRunning() ) { |
|
926 | 926 | // Avoid exception here: process is supposed to be running, but it might have stopped just |
927 | 927 | // after this line. In any case, let's silently discard the error, we cannot do anything. |
928 | - $this->doSignal($signal ?: 9, false); |
|
928 | + $this->doSignal( $signal ?: 9, false ); |
|
929 | 929 | } |
930 | 930 | } |
931 | 931 | |
932 | - if ($this->isRunning()) { |
|
933 | - if (isset($this->fallbackStatus['pid'])) { |
|
934 | - unset($this->fallbackStatus['pid']); |
|
932 | + if ( $this->isRunning() ) { |
|
933 | + if ( isset( $this->fallbackStatus[ 'pid' ] ) ) { |
|
934 | + unset( $this->fallbackStatus[ 'pid' ] ); |
|
935 | 935 | |
936 | - return $this->stop(0, $signal); |
|
936 | + return $this->stop( 0, $signal ); |
|
937 | 937 | } |
938 | 938 | $this->close(); |
939 | 939 | } |
@@ -946,13 +946,13 @@ discard block |
||
946 | 946 | * |
947 | 947 | * @internal |
948 | 948 | */ |
949 | - public function addOutput(string $line) |
|
949 | + public function addOutput( string $line ) |
|
950 | 950 | { |
951 | - $this->lastOutputTime = microtime(true); |
|
951 | + $this->lastOutputTime = microtime( true ); |
|
952 | 952 | |
953 | - fseek($this->stdout, 0, \SEEK_END); |
|
954 | - fwrite($this->stdout, $line); |
|
955 | - fseek($this->stdout, $this->incrementalOutputOffset); |
|
953 | + fseek( $this->stdout, 0, \SEEK_END ); |
|
954 | + fwrite( $this->stdout, $line ); |
|
955 | + fseek( $this->stdout, $this->incrementalOutputOffset ); |
|
956 | 956 | } |
957 | 957 | |
958 | 958 | /** |
@@ -960,13 +960,13 @@ discard block |
||
960 | 960 | * |
961 | 961 | * @internal |
962 | 962 | */ |
963 | - public function addErrorOutput(string $line) |
|
963 | + public function addErrorOutput( string $line ) |
|
964 | 964 | { |
965 | - $this->lastOutputTime = microtime(true); |
|
965 | + $this->lastOutputTime = microtime( true ); |
|
966 | 966 | |
967 | - fseek($this->stderr, 0, \SEEK_END); |
|
968 | - fwrite($this->stderr, $line); |
|
969 | - fseek($this->stderr, $this->incrementalErrorOutputOffset); |
|
967 | + fseek( $this->stderr, 0, \SEEK_END ); |
|
968 | + fwrite( $this->stderr, $line ); |
|
969 | + fseek( $this->stderr, $this->incrementalErrorOutputOffset ); |
|
970 | 970 | } |
971 | 971 | |
972 | 972 | /** |
@@ -986,7 +986,7 @@ discard block |
||
986 | 986 | */ |
987 | 987 | public function getCommandLine() |
988 | 988 | { |
989 | - return \is_array($this->commandline) ? implode(' ', array_map([$this, 'escapeArgument'], $this->commandline)) : $this->commandline; |
|
989 | + return \is_array( $this->commandline ) ? implode( ' ', array_map( [ $this, 'escapeArgument' ], $this->commandline ) ) : $this->commandline; |
|
990 | 990 | } |
991 | 991 | |
992 | 992 | /** |
@@ -1018,9 +1018,9 @@ discard block |
||
1018 | 1018 | * |
1019 | 1019 | * @throws InvalidArgumentException if the timeout is negative |
1020 | 1020 | */ |
1021 | - public function setTimeout(?float $timeout) |
|
1021 | + public function setTimeout( ?float $timeout ) |
|
1022 | 1022 | { |
1023 | - $this->timeout = $this->validateTimeout($timeout); |
|
1023 | + $this->timeout = $this->validateTimeout( $timeout ); |
|
1024 | 1024 | |
1025 | 1025 | return $this; |
1026 | 1026 | } |
@@ -1035,13 +1035,13 @@ discard block |
||
1035 | 1035 | * @throws LogicException if the output is disabled |
1036 | 1036 | * @throws InvalidArgumentException if the timeout is negative |
1037 | 1037 | */ |
1038 | - public function setIdleTimeout(?float $timeout) |
|
1038 | + public function setIdleTimeout( ?float $timeout ) |
|
1039 | 1039 | { |
1040 | - if (null !== $timeout && $this->outputDisabled) { |
|
1041 | - throw new LogicException('Idle timeout can not be set while the output is disabled.'); |
|
1040 | + if ( null !== $timeout && $this->outputDisabled ) { |
|
1041 | + throw new LogicException( 'Idle timeout can not be set while the output is disabled.' ); |
|
1042 | 1042 | } |
1043 | 1043 | |
1044 | - $this->idleTimeout = $this->validateTimeout($timeout); |
|
1044 | + $this->idleTimeout = $this->validateTimeout( $timeout ); |
|
1045 | 1045 | |
1046 | 1046 | return $this; |
1047 | 1047 | } |
@@ -1053,14 +1053,14 @@ discard block |
||
1053 | 1053 | * |
1054 | 1054 | * @throws RuntimeException In case the TTY mode is not supported |
1055 | 1055 | */ |
1056 | - public function setTty(bool $tty) |
|
1056 | + public function setTty( bool $tty ) |
|
1057 | 1057 | { |
1058 | - if ('\\' === \DIRECTORY_SEPARATOR && $tty) { |
|
1059 | - throw new RuntimeException('TTY mode is not supported on Windows platform.'); |
|
1058 | + if ( '\\' === \DIRECTORY_SEPARATOR && $tty ) { |
|
1059 | + throw new RuntimeException( 'TTY mode is not supported on Windows platform.' ); |
|
1060 | 1060 | } |
1061 | 1061 | |
1062 | - if ($tty && !self::isTtySupported()) { |
|
1063 | - throw new RuntimeException('TTY mode requires /dev/tty to be read/writable.'); |
|
1062 | + if ( $tty && ! self::isTtySupported() ) { |
|
1063 | + throw new RuntimeException( 'TTY mode requires /dev/tty to be read/writable.' ); |
|
1064 | 1064 | } |
1065 | 1065 | |
1066 | 1066 | $this->tty = $tty; |
@@ -1083,7 +1083,7 @@ discard block |
||
1083 | 1083 | * |
1084 | 1084 | * @return $this |
1085 | 1085 | */ |
1086 | - public function setPty(bool $bool) |
|
1086 | + public function setPty( bool $bool ) |
|
1087 | 1087 | { |
1088 | 1088 | $this->pty = $bool; |
1089 | 1089 | |
@@ -1107,7 +1107,7 @@ discard block |
||
1107 | 1107 | */ |
1108 | 1108 | public function getWorkingDirectory() |
1109 | 1109 | { |
1110 | - if (null === $this->cwd) { |
|
1110 | + if ( null === $this->cwd ) { |
|
1111 | 1111 | // getcwd() will return false if any one of the parent directories does not have |
1112 | 1112 | // the readable or search mode set, even if the current directory does |
1113 | 1113 | return getcwd() ?: null; |
@@ -1121,7 +1121,7 @@ discard block |
||
1121 | 1121 | * |
1122 | 1122 | * @return $this |
1123 | 1123 | */ |
1124 | - public function setWorkingDirectory(string $cwd) |
|
1124 | + public function setWorkingDirectory( string $cwd ) |
|
1125 | 1125 | { |
1126 | 1126 | $this->cwd = $cwd; |
1127 | 1127 | |
@@ -1153,11 +1153,11 @@ discard block |
||
1153 | 1153 | * |
1154 | 1154 | * @return $this |
1155 | 1155 | */ |
1156 | - public function setEnv(array $env) |
|
1156 | + public function setEnv( array $env ) |
|
1157 | 1157 | { |
1158 | 1158 | // Process can not handle env values that are arrays |
1159 | - $env = array_filter($env, function ($value) { |
|
1160 | - return !\is_array($value); |
|
1159 | + $env = array_filter( $env, function( $value ) { |
|
1160 | + return ! \is_array( $value ); |
|
1161 | 1161 | }); |
1162 | 1162 | |
1163 | 1163 | $this->env = $env; |
@@ -1186,13 +1186,13 @@ discard block |
||
1186 | 1186 | * |
1187 | 1187 | * @throws LogicException In case the process is running |
1188 | 1188 | */ |
1189 | - public function setInput($input) |
|
1189 | + public function setInput( $input ) |
|
1190 | 1190 | { |
1191 | - if ($this->isRunning()) { |
|
1192 | - throw new LogicException('Input can not be set while the process is running.'); |
|
1191 | + if ( $this->isRunning() ) { |
|
1192 | + throw new LogicException( 'Input can not be set while the process is running.' ); |
|
1193 | 1193 | } |
1194 | 1194 | |
1195 | - $this->input = ProcessUtils::validateInput(__METHOD__, $input); |
|
1195 | + $this->input = ProcessUtils::validateInput( __METHOD__, $input ); |
|
1196 | 1196 | |
1197 | 1197 | return $this; |
1198 | 1198 | } |
@@ -1207,20 +1207,20 @@ discard block |
||
1207 | 1207 | */ |
1208 | 1208 | public function checkTimeout() |
1209 | 1209 | { |
1210 | - if (self::STATUS_STARTED !== $this->status) { |
|
1210 | + if ( self::STATUS_STARTED !== $this->status ) { |
|
1211 | 1211 | return; |
1212 | 1212 | } |
1213 | 1213 | |
1214 | - if (null !== $this->timeout && $this->timeout < microtime(true) - $this->starttime) { |
|
1215 | - $this->stop(0); |
|
1214 | + if ( null !== $this->timeout && $this->timeout < microtime( true ) - $this->starttime ) { |
|
1215 | + $this->stop( 0 ); |
|
1216 | 1216 | |
1217 | - throw new ProcessTimedOutException($this, ProcessTimedOutException::TYPE_GENERAL); |
|
1217 | + throw new ProcessTimedOutException( $this, ProcessTimedOutException::TYPE_GENERAL ); |
|
1218 | 1218 | } |
1219 | 1219 | |
1220 | - if (null !== $this->idleTimeout && $this->idleTimeout < microtime(true) - $this->lastOutputTime) { |
|
1221 | - $this->stop(0); |
|
1220 | + if ( null !== $this->idleTimeout && $this->idleTimeout < microtime( true ) - $this->lastOutputTime ) { |
|
1221 | + $this->stop( 0 ); |
|
1222 | 1222 | |
1223 | - throw new ProcessTimedOutException($this, ProcessTimedOutException::TYPE_IDLE); |
|
1223 | + throw new ProcessTimedOutException( $this, ProcessTimedOutException::TYPE_IDLE ); |
|
1224 | 1224 | } |
1225 | 1225 | } |
1226 | 1226 | |
@@ -1229,8 +1229,8 @@ discard block |
||
1229 | 1229 | */ |
1230 | 1230 | public function getStartTime(): float |
1231 | 1231 | { |
1232 | - if (!$this->isStarted()) { |
|
1233 | - throw new LogicException('Start time is only available after process start.'); |
|
1232 | + if ( ! $this->isStarted() ) { |
|
1233 | + throw new LogicException( 'Start time is only available after process start.' ); |
|
1234 | 1234 | } |
1235 | 1235 | |
1236 | 1236 | return $this->starttime; |
@@ -1244,21 +1244,21 @@ discard block |
||
1244 | 1244 | * Enabling the "create_new_console" option allows a subprocess to continue |
1245 | 1245 | * to run after the main process exited, on both Windows and *nix |
1246 | 1246 | */ |
1247 | - public function setOptions(array $options) |
|
1247 | + public function setOptions( array $options ) |
|
1248 | 1248 | { |
1249 | - if ($this->isRunning()) { |
|
1250 | - throw new RuntimeException('Setting options while the process is running is not possible.'); |
|
1249 | + if ( $this->isRunning() ) { |
|
1250 | + throw new RuntimeException( 'Setting options while the process is running is not possible.' ); |
|
1251 | 1251 | } |
1252 | 1252 | |
1253 | 1253 | $defaultOptions = $this->options; |
1254 | - $existingOptions = ['blocking_pipes', 'create_process_group', 'create_new_console']; |
|
1254 | + $existingOptions = [ 'blocking_pipes', 'create_process_group', 'create_new_console' ]; |
|
1255 | 1255 | |
1256 | - foreach ($options as $key => $value) { |
|
1257 | - if (!\in_array($key, $existingOptions)) { |
|
1256 | + foreach ( $options as $key => $value ) { |
|
1257 | + if ( ! \in_array( $key, $existingOptions ) ) { |
|
1258 | 1258 | $this->options = $defaultOptions; |
1259 | - throw new LogicException(sprintf('Invalid option "%s" passed to "%s()". Supported options are "%s".', $key, __METHOD__, implode('", "', $existingOptions))); |
|
1259 | + throw new LogicException( sprintf( 'Invalid option "%s" passed to "%s()". Supported options are "%s".', $key, __METHOD__, implode( '", "', $existingOptions ) ) ); |
|
1260 | 1260 | } |
1261 | - $this->options[$key] = $value; |
|
1261 | + $this->options[ $key ] = $value; |
|
1262 | 1262 | } |
1263 | 1263 | } |
1264 | 1264 | |
@@ -1269,8 +1269,8 @@ discard block |
||
1269 | 1269 | { |
1270 | 1270 | static $isTtySupported; |
1271 | 1271 | |
1272 | - if (null === $isTtySupported) { |
|
1273 | - $isTtySupported = (bool) @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes); |
|
1272 | + if ( null === $isTtySupported ) { |
|
1273 | + $isTtySupported = (bool)@proc_open( 'echo 1 >/dev/null', [ [ 'file', '/dev/tty', 'r' ], [ 'file', '/dev/tty', 'w' ], [ 'file', '/dev/tty', 'w' ] ], $pipes ); |
|
1274 | 1274 | } |
1275 | 1275 | |
1276 | 1276 | return $isTtySupported; |
@@ -1285,15 +1285,15 @@ discard block |
||
1285 | 1285 | { |
1286 | 1286 | static $result; |
1287 | 1287 | |
1288 | - if (null !== $result) { |
|
1288 | + if ( null !== $result ) { |
|
1289 | 1289 | return $result; |
1290 | 1290 | } |
1291 | 1291 | |
1292 | - if ('\\' === \DIRECTORY_SEPARATOR) { |
|
1292 | + if ( '\\' === \DIRECTORY_SEPARATOR ) { |
|
1293 | 1293 | return $result = false; |
1294 | 1294 | } |
1295 | 1295 | |
1296 | - return $result = (bool) @proc_open('echo 1 >/dev/null', [['pty'], ['pty'], ['pty']], $pipes); |
|
1296 | + return $result = (bool)@proc_open( 'echo 1 >/dev/null', [ [ 'pty' ], [ 'pty' ], [ 'pty' ] ], $pipes ); |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | 1299 | /** |
@@ -1301,13 +1301,13 @@ discard block |
||
1301 | 1301 | */ |
1302 | 1302 | private function getDescriptors(): array |
1303 | 1303 | { |
1304 | - if ($this->input instanceof \Iterator) { |
|
1304 | + if ( $this->input instanceof \Iterator ) { |
|
1305 | 1305 | $this->input->rewind(); |
1306 | 1306 | } |
1307 | - if ('\\' === \DIRECTORY_SEPARATOR) { |
|
1308 | - $this->processPipes = new WindowsPipes($this->input, !$this->outputDisabled || $this->hasCallback); |
|
1307 | + if ( '\\' === \DIRECTORY_SEPARATOR ) { |
|
1308 | + $this->processPipes = new WindowsPipes( $this->input, ! $this->outputDisabled || $this->hasCallback ); |
|
1309 | 1309 | } else { |
1310 | - $this->processPipes = new UnixPipes($this->isTty(), $this->isPty(), $this->input, !$this->outputDisabled || $this->hasCallback); |
|
1310 | + $this->processPipes = new UnixPipes( $this->isTty(), $this->isPty(), $this->input, ! $this->outputDisabled || $this->hasCallback ); |
|
1311 | 1311 | } |
1312 | 1312 | |
1313 | 1313 | return $this->processPipes->getDescriptors(); |
@@ -1323,24 +1323,24 @@ discard block |
||
1323 | 1323 | * |
1324 | 1324 | * @return \Closure A PHP closure |
1325 | 1325 | */ |
1326 | - protected function buildCallback(callable $callback = null) |
|
1326 | + protected function buildCallback( callable $callback = null ) |
|
1327 | 1327 | { |
1328 | - if ($this->outputDisabled) { |
|
1329 | - return function ($type, $data) use ($callback): bool { |
|
1330 | - return null !== $callback && $callback($type, $data); |
|
1328 | + if ( $this->outputDisabled ) { |
|
1329 | + return function( $type, $data ) use ( $callback ): bool { |
|
1330 | + return null !== $callback && $callback( $type, $data ); |
|
1331 | 1331 | }; |
1332 | 1332 | } |
1333 | 1333 | |
1334 | 1334 | $out = self::OUT; |
1335 | 1335 | |
1336 | - return function ($type, $data) use ($callback, $out): bool { |
|
1337 | - if ($out == $type) { |
|
1338 | - $this->addOutput($data); |
|
1336 | + return function( $type, $data ) use ( $callback, $out ): bool { |
|
1337 | + if ( $out == $type ) { |
|
1338 | + $this->addOutput( $data ); |
|
1339 | 1339 | } else { |
1340 | - $this->addErrorOutput($data); |
|
1340 | + $this->addErrorOutput( $data ); |
|
1341 | 1341 | } |
1342 | 1342 | |
1343 | - return null !== $callback && $callback($type, $data); |
|
1343 | + return null !== $callback && $callback( $type, $data ); |
|
1344 | 1344 | }; |
1345 | 1345 | } |
1346 | 1346 | |
@@ -1349,22 +1349,22 @@ discard block |
||
1349 | 1349 | * |
1350 | 1350 | * @param bool $blocking Whether to use a blocking read call |
1351 | 1351 | */ |
1352 | - protected function updateStatus(bool $blocking) |
|
1352 | + protected function updateStatus( bool $blocking ) |
|
1353 | 1353 | { |
1354 | - if (self::STATUS_STARTED !== $this->status) { |
|
1354 | + if ( self::STATUS_STARTED !== $this->status ) { |
|
1355 | 1355 | return; |
1356 | 1356 | } |
1357 | 1357 | |
1358 | - $this->processInformation = proc_get_status($this->process); |
|
1359 | - $running = $this->processInformation['running']; |
|
1358 | + $this->processInformation = proc_get_status( $this->process ); |
|
1359 | + $running = $this->processInformation[ 'running' ]; |
|
1360 | 1360 | |
1361 | - $this->readPipes($running && $blocking, '\\' !== \DIRECTORY_SEPARATOR || !$running); |
|
1361 | + $this->readPipes( $running && $blocking, '\\' !== \DIRECTORY_SEPARATOR || ! $running ); |
|
1362 | 1362 | |
1363 | - if ($this->fallbackStatus && $this->isSigchildEnabled()) { |
|
1363 | + if ( $this->fallbackStatus && $this->isSigchildEnabled() ) { |
|
1364 | 1364 | $this->processInformation = $this->fallbackStatus + $this->processInformation; |
1365 | 1365 | } |
1366 | 1366 | |
1367 | - if (!$running) { |
|
1367 | + if ( ! $running ) { |
|
1368 | 1368 | $this->close(); |
1369 | 1369 | } |
1370 | 1370 | } |
@@ -1376,18 +1376,18 @@ discard block |
||
1376 | 1376 | */ |
1377 | 1377 | protected function isSigchildEnabled() |
1378 | 1378 | { |
1379 | - if (null !== self::$sigchild) { |
|
1379 | + if ( null !== self::$sigchild ) { |
|
1380 | 1380 | return self::$sigchild; |
1381 | 1381 | } |
1382 | 1382 | |
1383 | - if (!\function_exists('phpinfo')) { |
|
1383 | + if ( ! \function_exists( 'phpinfo' ) ) { |
|
1384 | 1384 | return self::$sigchild = false; |
1385 | 1385 | } |
1386 | 1386 | |
1387 | 1387 | ob_start(); |
1388 | - phpinfo(\INFO_GENERAL); |
|
1388 | + phpinfo( \INFO_GENERAL ); |
|
1389 | 1389 | |
1390 | - return self::$sigchild = str_contains(ob_get_clean(), '--enable-sigchild'); |
|
1390 | + return self::$sigchild = str_contains( ob_get_clean(), '--enable-sigchild' ); |
|
1391 | 1391 | } |
1392 | 1392 | |
1393 | 1393 | /** |
@@ -1398,15 +1398,15 @@ discard block |
||
1398 | 1398 | * |
1399 | 1399 | * @throws LogicException in case output has been disabled or process is not started |
1400 | 1400 | */ |
1401 | - private function readPipesForOutput(string $caller, bool $blocking = false) |
|
1401 | + private function readPipesForOutput( string $caller, bool $blocking = false ) |
|
1402 | 1402 | { |
1403 | - if ($this->outputDisabled) { |
|
1404 | - throw new LogicException('Output has been disabled.'); |
|
1403 | + if ( $this->outputDisabled ) { |
|
1404 | + throw new LogicException( 'Output has been disabled.' ); |
|
1405 | 1405 | } |
1406 | 1406 | |
1407 | - $this->requireProcessIsStarted($caller); |
|
1407 | + $this->requireProcessIsStarted( $caller ); |
|
1408 | 1408 | |
1409 | - $this->updateStatus($blocking); |
|
1409 | + $this->updateStatus( $blocking ); |
|
1410 | 1410 | } |
1411 | 1411 | |
1412 | 1412 | /** |
@@ -1414,14 +1414,14 @@ discard block |
||
1414 | 1414 | * |
1415 | 1415 | * @throws InvalidArgumentException if the given timeout is a negative number |
1416 | 1416 | */ |
1417 | - private function validateTimeout(?float $timeout): ?float |
|
1417 | + private function validateTimeout( ?float $timeout ): ?float |
|
1418 | 1418 | { |
1419 | - $timeout = (float) $timeout; |
|
1419 | + $timeout = (float)$timeout; |
|
1420 | 1420 | |
1421 | - if (0.0 === $timeout) { |
|
1421 | + if ( 0.0 === $timeout ) { |
|
1422 | 1422 | $timeout = null; |
1423 | - } elseif ($timeout < 0) { |
|
1424 | - throw new InvalidArgumentException('The timeout value must be a valid positive integer or float number.'); |
|
1423 | + } elseif ( $timeout < 0 ) { |
|
1424 | + throw new InvalidArgumentException( 'The timeout value must be a valid positive integer or float number.' ); |
|
1425 | 1425 | } |
1426 | 1426 | |
1427 | 1427 | return $timeout; |
@@ -1433,16 +1433,16 @@ discard block |
||
1433 | 1433 | * @param bool $blocking Whether to use blocking calls or not |
1434 | 1434 | * @param bool $close Whether to close file handles or not |
1435 | 1435 | */ |
1436 | - private function readPipes(bool $blocking, bool $close) |
|
1436 | + private function readPipes( bool $blocking, bool $close ) |
|
1437 | 1437 | { |
1438 | - $result = $this->processPipes->readAndWrite($blocking, $close); |
|
1438 | + $result = $this->processPipes->readAndWrite( $blocking, $close ); |
|
1439 | 1439 | |
1440 | 1440 | $callback = $this->callback; |
1441 | - foreach ($result as $type => $data) { |
|
1442 | - if (3 !== $type) { |
|
1443 | - $callback(self::STDOUT === $type ? self::OUT : self::ERR, $data); |
|
1444 | - } elseif (!isset($this->fallbackStatus['signaled'])) { |
|
1445 | - $this->fallbackStatus['exitcode'] = (int) $data; |
|
1441 | + foreach ( $result as $type => $data ) { |
|
1442 | + if ( 3 !== $type ) { |
|
1443 | + $callback( self::STDOUT === $type ? self::OUT : self::ERR, $data ); |
|
1444 | + } elseif ( ! isset( $this->fallbackStatus[ 'signaled' ] ) ) { |
|
1445 | + $this->fallbackStatus[ 'exitcode' ] = (int)$data; |
|
1446 | 1446 | } |
1447 | 1447 | } |
1448 | 1448 | } |
@@ -1455,19 +1455,19 @@ discard block |
||
1455 | 1455 | private function close(): int |
1456 | 1456 | { |
1457 | 1457 | $this->processPipes->close(); |
1458 | - if (\is_resource($this->process)) { |
|
1459 | - proc_close($this->process); |
|
1458 | + if ( \is_resource( $this->process ) ) { |
|
1459 | + proc_close( $this->process ); |
|
1460 | 1460 | } |
1461 | - $this->exitcode = $this->processInformation['exitcode']; |
|
1461 | + $this->exitcode = $this->processInformation[ 'exitcode' ]; |
|
1462 | 1462 | $this->status = self::STATUS_TERMINATED; |
1463 | 1463 | |
1464 | 1464 | if (-1 === $this->exitcode) { |
1465 | - if ($this->processInformation['signaled'] && 0 < $this->processInformation['termsig']) { |
|
1465 | + if ( $this->processInformation[ 'signaled' ] && 0 < $this->processInformation[ 'termsig' ] ) { |
|
1466 | 1466 | // if process has been signaled, no exitcode but a valid termsig, apply Unix convention |
1467 | - $this->exitcode = 128 + $this->processInformation['termsig']; |
|
1468 | - } elseif ($this->isSigchildEnabled()) { |
|
1469 | - $this->processInformation['signaled'] = true; |
|
1470 | - $this->processInformation['termsig'] = -1; |
|
1467 | + $this->exitcode = 128 + $this->processInformation[ 'termsig' ]; |
|
1468 | + } elseif ( $this->isSigchildEnabled() ) { |
|
1469 | + $this->processInformation[ 'signaled' ] = true; |
|
1470 | + $this->processInformation[ 'termsig' ] = -1; |
|
1471 | 1471 | } |
1472 | 1472 | } |
1473 | 1473 | |
@@ -1487,10 +1487,10 @@ discard block |
||
1487 | 1487 | $this->starttime = null; |
1488 | 1488 | $this->callback = null; |
1489 | 1489 | $this->exitcode = null; |
1490 | - $this->fallbackStatus = []; |
|
1490 | + $this->fallbackStatus = [ ]; |
|
1491 | 1491 | $this->processInformation = null; |
1492 | - $this->stdout = fopen('php://temp/maxmemory:'.(1024 * 1024), 'w+'); |
|
1493 | - $this->stderr = fopen('php://temp/maxmemory:'.(1024 * 1024), 'w+'); |
|
1492 | + $this->stdout = fopen( 'php://temp/maxmemory:' . ( 1024 * 1024 ), 'w+' ); |
|
1493 | + $this->stderr = fopen( 'php://temp/maxmemory:' . ( 1024 * 1024 ), 'w+' ); |
|
1494 | 1494 | $this->process = null; |
1495 | 1495 | $this->latestSignal = null; |
1496 | 1496 | $this->status = self::STATUS_READY; |
@@ -1510,36 +1510,36 @@ discard block |
||
1510 | 1510 | * @throws RuntimeException In case --enable-sigchild is activated and the process can't be killed |
1511 | 1511 | * @throws RuntimeException In case of failure |
1512 | 1512 | */ |
1513 | - private function doSignal(int $signal, bool $throwException): bool |
|
1513 | + private function doSignal( int $signal, bool $throwException ): bool |
|
1514 | 1514 | { |
1515 | - if (null === $pid = $this->getPid()) { |
|
1516 | - if ($throwException) { |
|
1517 | - throw new LogicException('Can not send signal on a non running process.'); |
|
1515 | + if ( null === $pid = $this->getPid() ) { |
|
1516 | + if ( $throwException ) { |
|
1517 | + throw new LogicException( 'Can not send signal on a non running process.' ); |
|
1518 | 1518 | } |
1519 | 1519 | |
1520 | 1520 | return false; |
1521 | 1521 | } |
1522 | 1522 | |
1523 | - if ('\\' === \DIRECTORY_SEPARATOR) { |
|
1524 | - exec(sprintf('taskkill /F /T /PID %d 2>&1', $pid), $output, $exitCode); |
|
1525 | - if ($exitCode && $this->isRunning()) { |
|
1526 | - if ($throwException) { |
|
1527 | - throw new RuntimeException(sprintf('Unable to kill the process (%s).', implode(' ', $output))); |
|
1523 | + if ( '\\' === \DIRECTORY_SEPARATOR ) { |
|
1524 | + exec( sprintf( 'taskkill /F /T /PID %d 2>&1', $pid ), $output, $exitCode ); |
|
1525 | + if ( $exitCode && $this->isRunning() ) { |
|
1526 | + if ( $throwException ) { |
|
1527 | + throw new RuntimeException( sprintf( 'Unable to kill the process (%s).', implode( ' ', $output ) ) ); |
|
1528 | 1528 | } |
1529 | 1529 | |
1530 | 1530 | return false; |
1531 | 1531 | } |
1532 | 1532 | } else { |
1533 | - if (!$this->isSigchildEnabled()) { |
|
1534 | - $ok = @proc_terminate($this->process, $signal); |
|
1535 | - } elseif (\function_exists('posix_kill')) { |
|
1536 | - $ok = @posix_kill($pid, $signal); |
|
1537 | - } elseif ($ok = proc_open(sprintf('kill -%d %d', $signal, $pid), [2 => ['pipe', 'w']], $pipes)) { |
|
1538 | - $ok = false === fgets($pipes[2]); |
|
1533 | + if ( ! $this->isSigchildEnabled() ) { |
|
1534 | + $ok = @proc_terminate( $this->process, $signal ); |
|
1535 | + } elseif ( \function_exists( 'posix_kill' ) ) { |
|
1536 | + $ok = @posix_kill( $pid, $signal ); |
|
1537 | + } elseif ( $ok = proc_open( sprintf( 'kill -%d %d', $signal, $pid ), [ 2 => [ 'pipe', 'w' ] ], $pipes ) ) { |
|
1538 | + $ok = false === fgets( $pipes[ 2 ] ); |
|
1539 | 1539 | } |
1540 | - if (!$ok) { |
|
1541 | - if ($throwException) { |
|
1542 | - throw new RuntimeException(sprintf('Error while sending signal "%s".', $signal)); |
|
1540 | + if ( ! $ok ) { |
|
1541 | + if ( $throwException ) { |
|
1542 | + throw new RuntimeException( sprintf( 'Error while sending signal "%s".', $signal ) ); |
|
1543 | 1543 | } |
1544 | 1544 | |
1545 | 1545 | return false; |
@@ -1547,18 +1547,18 @@ discard block |
||
1547 | 1547 | } |
1548 | 1548 | |
1549 | 1549 | $this->latestSignal = $signal; |
1550 | - $this->fallbackStatus['signaled'] = true; |
|
1551 | - $this->fallbackStatus['exitcode'] = -1; |
|
1552 | - $this->fallbackStatus['termsig'] = $this->latestSignal; |
|
1550 | + $this->fallbackStatus[ 'signaled' ] = true; |
|
1551 | + $this->fallbackStatus[ 'exitcode' ] = -1; |
|
1552 | + $this->fallbackStatus[ 'termsig' ] = $this->latestSignal; |
|
1553 | 1553 | |
1554 | 1554 | return true; |
1555 | 1555 | } |
1556 | 1556 | |
1557 | - private function prepareWindowsCommandLine(string $cmd, array &$env): string |
|
1557 | + private function prepareWindowsCommandLine( string $cmd, array &$env ): string |
|
1558 | 1558 | { |
1559 | - $uid = uniqid('', true); |
|
1559 | + $uid = uniqid( '', true ); |
|
1560 | 1560 | $varCount = 0; |
1561 | - $varCache = []; |
|
1561 | + $varCache = [ ]; |
|
1562 | 1562 | $cmd = preg_replace_callback( |
1563 | 1563 | '/"(?:( |
1564 | 1564 | [^"%!^]*+ |
@@ -1567,34 +1567,34 @@ discard block |
||
1567 | 1567 | [^"%!^]*+ |
1568 | 1568 | )++ |
1569 | 1569 | ) | [^"]*+ )"/x', |
1570 | - function ($m) use (&$env, &$varCache, &$varCount, $uid) { |
|
1571 | - if (!isset($m[1])) { |
|
1572 | - return $m[0]; |
|
1570 | + function( $m ) use ( &$env, &$varCache, &$varCount, $uid ) { |
|
1571 | + if ( ! isset( $m[ 1 ] ) ) { |
|
1572 | + return $m[ 0 ]; |
|
1573 | 1573 | } |
1574 | - if (isset($varCache[$m[0]])) { |
|
1575 | - return $varCache[$m[0]]; |
|
1574 | + if ( isset( $varCache[ $m[ 0 ] ] ) ) { |
|
1575 | + return $varCache[ $m[ 0 ] ]; |
|
1576 | 1576 | } |
1577 | - if (str_contains($value = $m[1], "\0")) { |
|
1578 | - $value = str_replace("\0", '?', $value); |
|
1577 | + if ( str_contains( $value = $m[ 1 ], "\0" ) ) { |
|
1578 | + $value = str_replace( "\0", '?', $value ); |
|
1579 | 1579 | } |
1580 | - if (false === strpbrk($value, "\"%!\n")) { |
|
1581 | - return '"'.$value.'"'; |
|
1580 | + if ( false === strpbrk( $value, "\"%!\n" ) ) { |
|
1581 | + return '"' . $value . '"'; |
|
1582 | 1582 | } |
1583 | 1583 | |
1584 | - $value = str_replace(['!LF!', '"^!"', '"^%"', '"^^"', '""'], ["\n", '!', '%', '^', '"'], $value); |
|
1585 | - $value = '"'.preg_replace('/(\\\\*)"/', '$1$1\\"', $value).'"'; |
|
1586 | - $var = $uid.++$varCount; |
|
1584 | + $value = str_replace( [ '!LF!', '"^!"', '"^%"', '"^^"', '""' ], [ "\n", '!', '%', '^', '"' ], $value ); |
|
1585 | + $value = '"' . preg_replace( '/(\\\\*)"/', '$1$1\\"', $value ) . '"'; |
|
1586 | + $var = $uid . ++$varCount; |
|
1587 | 1587 | |
1588 | - $env[$var] = $value; |
|
1588 | + $env[ $var ] = $value; |
|
1589 | 1589 | |
1590 | - return $varCache[$m[0]] = '!'.$var.'!'; |
|
1590 | + return $varCache[ $m[ 0 ] ] = '!' . $var . '!'; |
|
1591 | 1591 | }, |
1592 | 1592 | $cmd |
1593 | 1593 | ); |
1594 | 1594 | |
1595 | - $cmd = 'cmd /V:ON /E:ON /D /C ('.str_replace("\n", ' ', $cmd).')'; |
|
1596 | - foreach ($this->processPipes->getFiles() as $offset => $filename) { |
|
1597 | - $cmd .= ' '.$offset.'>"'.$filename.'"'; |
|
1595 | + $cmd = 'cmd /V:ON /E:ON /D /C (' . str_replace( "\n", ' ', $cmd ) . ')'; |
|
1596 | + foreach ( $this->processPipes->getFiles() as $offset => $filename ) { |
|
1597 | + $cmd .= ' ' . $offset . '>"' . $filename . '"'; |
|
1598 | 1598 | } |
1599 | 1599 | |
1600 | 1600 | return $cmd; |
@@ -1605,10 +1605,10 @@ discard block |
||
1605 | 1605 | * |
1606 | 1606 | * @throws LogicException if the process has not run |
1607 | 1607 | */ |
1608 | - private function requireProcessIsStarted(string $functionName) |
|
1608 | + private function requireProcessIsStarted( string $functionName ) |
|
1609 | 1609 | { |
1610 | - if (!$this->isStarted()) { |
|
1611 | - throw new LogicException(sprintf('Process must be started before calling "%s()".', $functionName)); |
|
1610 | + if ( ! $this->isStarted() ) { |
|
1611 | + throw new LogicException( sprintf( 'Process must be started before calling "%s()".', $functionName ) ); |
|
1612 | 1612 | } |
1613 | 1613 | } |
1614 | 1614 | |
@@ -1617,59 +1617,59 @@ discard block |
||
1617 | 1617 | * |
1618 | 1618 | * @throws LogicException if the process is not yet terminated |
1619 | 1619 | */ |
1620 | - private function requireProcessIsTerminated(string $functionName) |
|
1620 | + private function requireProcessIsTerminated( string $functionName ) |
|
1621 | 1621 | { |
1622 | - if (!$this->isTerminated()) { |
|
1623 | - throw new LogicException(sprintf('Process must be terminated before calling "%s()".', $functionName)); |
|
1622 | + if ( ! $this->isTerminated() ) { |
|
1623 | + throw new LogicException( sprintf( 'Process must be terminated before calling "%s()".', $functionName ) ); |
|
1624 | 1624 | } |
1625 | 1625 | } |
1626 | 1626 | |
1627 | 1627 | /** |
1628 | 1628 | * Escapes a string to be used as a shell argument. |
1629 | 1629 | */ |
1630 | - private function escapeArgument(?string $argument): string |
|
1630 | + private function escapeArgument( ?string $argument ): string |
|
1631 | 1631 | { |
1632 | - if ('' === $argument || null === $argument) { |
|
1632 | + if ( '' === $argument || null === $argument ) { |
|
1633 | 1633 | return '""'; |
1634 | 1634 | } |
1635 | - if ('\\' !== \DIRECTORY_SEPARATOR) { |
|
1636 | - return "'".str_replace("'", "'\\''", $argument)."'"; |
|
1635 | + if ( '\\' !== \DIRECTORY_SEPARATOR ) { |
|
1636 | + return "'" . str_replace( "'", "'\\''", $argument ) . "'"; |
|
1637 | 1637 | } |
1638 | - if (str_contains($argument, "\0")) { |
|
1639 | - $argument = str_replace("\0", '?', $argument); |
|
1638 | + if ( str_contains( $argument, "\0" ) ) { |
|
1639 | + $argument = str_replace( "\0", '?', $argument ); |
|
1640 | 1640 | } |
1641 | - if (!preg_match('/[\/()%!^"<>&|\s]/', $argument)) { |
|
1641 | + if ( ! preg_match( '/[\/()%!^"<>&|\s]/', $argument ) ) { |
|
1642 | 1642 | return $argument; |
1643 | 1643 | } |
1644 | - $argument = preg_replace('/(\\\\+)$/', '$1$1', $argument); |
|
1644 | + $argument = preg_replace( '/(\\\\+)$/', '$1$1', $argument ); |
|
1645 | 1645 | |
1646 | - return '"'.str_replace(['"', '^', '%', '!', "\n"], ['""', '"^^"', '"^%"', '"^!"', '!LF!'], $argument).'"'; |
|
1646 | + return '"' . str_replace( [ '"', '^', '%', '!', "\n" ], [ '""', '"^^"', '"^%"', '"^!"', '!LF!' ], $argument ) . '"'; |
|
1647 | 1647 | } |
1648 | 1648 | |
1649 | - private function replacePlaceholders(string $commandline, array $env) |
|
1649 | + private function replacePlaceholders( string $commandline, array $env ) |
|
1650 | 1650 | { |
1651 | - return preg_replace_callback('/"\$\{:([_a-zA-Z]++[_a-zA-Z0-9]*+)\}"/', function ($matches) use ($commandline, $env) { |
|
1652 | - if (!isset($env[$matches[1]]) || false === $env[$matches[1]]) { |
|
1653 | - throw new InvalidArgumentException(sprintf('Command line is missing a value for parameter "%s": ', $matches[1]).$commandline); |
|
1651 | + return preg_replace_callback( '/"\$\{:([_a-zA-Z]++[_a-zA-Z0-9]*+)\}"/', function( $matches ) use ( $commandline, $env ) { |
|
1652 | + if ( ! isset( $env[ $matches[ 1 ] ] ) || false === $env[ $matches[ 1 ] ] ) { |
|
1653 | + throw new InvalidArgumentException( sprintf( 'Command line is missing a value for parameter "%s": ', $matches[ 1 ] ) . $commandline ); |
|
1654 | 1654 | } |
1655 | 1655 | |
1656 | - return $this->escapeArgument($env[$matches[1]]); |
|
1657 | - }, $commandline); |
|
1656 | + return $this->escapeArgument( $env[ $matches[ 1 ] ] ); |
|
1657 | + }, $commandline ); |
|
1658 | 1658 | } |
1659 | 1659 | |
1660 | 1660 | private function getDefaultEnv(): array |
1661 | 1661 | { |
1662 | - $env = []; |
|
1662 | + $env = [ ]; |
|
1663 | 1663 | |
1664 | - foreach ($_SERVER as $k => $v) { |
|
1665 | - if (\is_string($v) && false !== $v = getenv($k)) { |
|
1666 | - $env[$k] = $v; |
|
1664 | + foreach ( $_SERVER as $k => $v ) { |
|
1665 | + if ( \is_string( $v ) && false !== $v = getenv( $k ) ) { |
|
1666 | + $env[ $k ] = $v; |
|
1667 | 1667 | } |
1668 | 1668 | } |
1669 | 1669 | |
1670 | - foreach ($_ENV as $k => $v) { |
|
1671 | - if (\is_string($v)) { |
|
1672 | - $env[$k] = $v; |
|
1670 | + foreach ( $_ENV as $k => $v ) { |
|
1671 | + if ( \is_string( $v ) ) { |
|
1672 | + $env[ $k ] = $v; |
|
1673 | 1673 | } |
1674 | 1674 | } |
1675 | 1675 |
@@ -11,32 +11,32 @@ |
||
11 | 11 | |
12 | 12 | use Symfony\Polyfill\Php80 as p; |
13 | 13 | |
14 | -if (\PHP_VERSION_ID >= 80000) { |
|
14 | +if ( \PHP_VERSION_ID >= 80000 ) { |
|
15 | 15 | return; |
16 | 16 | } |
17 | 17 | |
18 | -if (!defined('FILTER_VALIDATE_BOOL') && defined('FILTER_VALIDATE_BOOLEAN')) { |
|
19 | - define('FILTER_VALIDATE_BOOL', \FILTER_VALIDATE_BOOLEAN); |
|
18 | +if ( ! defined( 'FILTER_VALIDATE_BOOL' ) && defined( 'FILTER_VALIDATE_BOOLEAN' ) ) { |
|
19 | + define( 'FILTER_VALIDATE_BOOL', \FILTER_VALIDATE_BOOLEAN ); |
|
20 | 20 | } |
21 | 21 | |
22 | -if (!function_exists('fdiv')) { |
|
23 | - function fdiv(float $num1, float $num2): float { return p\Php80::fdiv($num1, $num2); } |
|
22 | +if ( ! function_exists( 'fdiv' ) ) { |
|
23 | + function fdiv( float $num1, float $num2 ): float { return p\Php80::fdiv( $num1, $num2 ); } |
|
24 | 24 | } |
25 | -if (!function_exists('preg_last_error_msg')) { |
|
25 | +if ( ! function_exists( 'preg_last_error_msg' ) ) { |
|
26 | 26 | function preg_last_error_msg(): string { return p\Php80::preg_last_error_msg(); } |
27 | 27 | } |
28 | -if (!function_exists('str_contains')) { |
|
29 | - function str_contains(?string $haystack, ?string $needle): bool { return p\Php80::str_contains($haystack ?? '', $needle ?? ''); } |
|
28 | +if ( ! function_exists( 'str_contains' ) ) { |
|
29 | + function str_contains( ?string $haystack, ?string $needle ): bool { return p\Php80::str_contains( $haystack ?? '', $needle ?? '' ); } |
|
30 | 30 | } |
31 | -if (!function_exists('str_starts_with')) { |
|
32 | - function str_starts_with(?string $haystack, ?string $needle): bool { return p\Php80::str_starts_with($haystack ?? '', $needle ?? ''); } |
|
31 | +if ( ! function_exists( 'str_starts_with' ) ) { |
|
32 | + function str_starts_with( ?string $haystack, ?string $needle ): bool { return p\Php80::str_starts_with( $haystack ?? '', $needle ?? '' ); } |
|
33 | 33 | } |
34 | -if (!function_exists('str_ends_with')) { |
|
35 | - function str_ends_with(?string $haystack, ?string $needle): bool { return p\Php80::str_ends_with($haystack ?? '', $needle ?? ''); } |
|
34 | +if ( ! function_exists( 'str_ends_with' ) ) { |
|
35 | + function str_ends_with( ?string $haystack, ?string $needle ): bool { return p\Php80::str_ends_with( $haystack ?? '', $needle ?? '' ); } |
|
36 | 36 | } |
37 | -if (!function_exists('get_debug_type')) { |
|
38 | - function get_debug_type($value): string { return p\Php80::get_debug_type($value); } |
|
37 | +if ( ! function_exists( 'get_debug_type' ) ) { |
|
38 | + function get_debug_type( $value ): string { return p\Php80::get_debug_type( $value ); } |
|
39 | 39 | } |
40 | -if (!function_exists('get_resource_id')) { |
|
41 | - function get_resource_id($resource): int { return p\Php80::get_resource_id($resource); } |
|
40 | +if ( ! function_exists( 'get_resource_id' ) ) { |
|
41 | + function get_resource_id( $resource ): int { return p\Php80::get_resource_id( $resource ); } |
|
42 | 42 | } |
@@ -20,55 +20,55 @@ discard block |
||
20 | 20 | */ |
21 | 21 | final class Php80 |
22 | 22 | { |
23 | - public static function fdiv(float $dividend, float $divisor): float |
|
23 | + public static function fdiv( float $dividend, float $divisor ): float |
|
24 | 24 | { |
25 | - return @($dividend / $divisor); |
|
25 | + return @( $dividend / $divisor ); |
|
26 | 26 | } |
27 | 27 | |
28 | - public static function get_debug_type($value): string |
|
28 | + public static function get_debug_type( $value ): string |
|
29 | 29 | { |
30 | - switch (true) { |
|
30 | + switch ( true ) { |
|
31 | 31 | case null === $value: return 'null'; |
32 | - case \is_bool($value): return 'bool'; |
|
33 | - case \is_string($value): return 'string'; |
|
34 | - case \is_array($value): return 'array'; |
|
35 | - case \is_int($value): return 'int'; |
|
36 | - case \is_float($value): return 'float'; |
|
37 | - case \is_object($value): break; |
|
32 | + case \is_bool( $value ): return 'bool'; |
|
33 | + case \is_string( $value ): return 'string'; |
|
34 | + case \is_array( $value ): return 'array'; |
|
35 | + case \is_int( $value ): return 'int'; |
|
36 | + case \is_float( $value ): return 'float'; |
|
37 | + case \is_object( $value ): break; |
|
38 | 38 | case $value instanceof \__PHP_Incomplete_Class: return '__PHP_Incomplete_Class'; |
39 | 39 | default: |
40 | - if (null === $type = @get_resource_type($value)) { |
|
40 | + if ( null === $type = @get_resource_type( $value ) ) { |
|
41 | 41 | return 'unknown'; |
42 | 42 | } |
43 | 43 | |
44 | - if ('Unknown' === $type) { |
|
44 | + if ( 'Unknown' === $type ) { |
|
45 | 45 | $type = 'closed'; |
46 | 46 | } |
47 | 47 | |
48 | 48 | return "resource ($type)"; |
49 | 49 | } |
50 | 50 | |
51 | - $class = \get_class($value); |
|
51 | + $class = \get_class( $value ); |
|
52 | 52 | |
53 | - if (false === strpos($class, '@')) { |
|
53 | + if ( false === strpos( $class, '@' ) ) { |
|
54 | 54 | return $class; |
55 | 55 | } |
56 | 56 | |
57 | - return (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous'; |
|
57 | + return ( get_parent_class( $class ) ?: key( class_implements( $class ) ) ?: 'class' ) . '@anonymous'; |
|
58 | 58 | } |
59 | 59 | |
60 | - public static function get_resource_id($res): int |
|
60 | + public static function get_resource_id( $res ): int |
|
61 | 61 | { |
62 | - if (!\is_resource($res) && null === @get_resource_type($res)) { |
|
63 | - throw new \TypeError(sprintf('Argument 1 passed to get_resource_id() must be of the type resource, %s given', get_debug_type($res))); |
|
62 | + if ( ! \is_resource( $res ) && null === @get_resource_type( $res ) ) { |
|
63 | + throw new \TypeError( sprintf( 'Argument 1 passed to get_resource_id() must be of the type resource, %s given', get_debug_type( $res ) ) ); |
|
64 | 64 | } |
65 | 65 | |
66 | - return (int) $res; |
|
66 | + return (int)$res; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | public static function preg_last_error_msg(): string |
70 | 70 | { |
71 | - switch (preg_last_error()) { |
|
71 | + switch ( preg_last_error() ) { |
|
72 | 72 | case \PREG_INTERNAL_ERROR: |
73 | 73 | return 'Internal error'; |
74 | 74 | case \PREG_BAD_UTF8_ERROR: |
@@ -88,18 +88,18 @@ discard block |
||
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | - public static function str_contains(string $haystack, string $needle): bool |
|
91 | + public static function str_contains( string $haystack, string $needle ): bool |
|
92 | 92 | { |
93 | - return '' === $needle || false !== strpos($haystack, $needle); |
|
93 | + return '' === $needle || false !== strpos( $haystack, $needle ); |
|
94 | 94 | } |
95 | 95 | |
96 | - public static function str_starts_with(string $haystack, string $needle): bool |
|
96 | + public static function str_starts_with( string $haystack, string $needle ): bool |
|
97 | 97 | { |
98 | - return 0 === strncmp($haystack, $needle, \strlen($needle)); |
|
98 | + return 0 === strncmp( $haystack, $needle, \strlen( $needle ) ); |
|
99 | 99 | } |
100 | 100 | |
101 | - public static function str_ends_with(string $haystack, string $needle): bool |
|
101 | + public static function str_ends_with( string $haystack, string $needle ): bool |
|
102 | 102 | { |
103 | - return '' === $needle || ('' !== $haystack && 0 === substr_compare($haystack, $needle, -\strlen($needle))); |
|
103 | + return '' === $needle || ( '' !== $haystack && 0 === substr_compare( $haystack, $needle, -\strlen( $needle ) ) ); |
|
104 | 104 | } |
105 | 105 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (\PHP_VERSION_ID < 80000) { |
|
3 | +if ( \PHP_VERSION_ID < 80000 ) { |
|
4 | 4 | interface Stringable |
5 | 5 | { |
6 | 6 | /** |
@@ -15,7 +15,7 @@ |
||
15 | 15 | /** @var int */ |
16 | 16 | public $flags; |
17 | 17 | |
18 | - public function __construct(int $flags = self::TARGET_ALL) |
|
18 | + public function __construct( int $flags = self::TARGET_ALL ) |
|
19 | 19 | { |
20 | 20 | $this->flags = $flags; |
21 | 21 | } |
@@ -11,21 +11,21 @@ |
||
11 | 11 | |
12 | 12 | use Symfony\Polyfill\Php73 as p; |
13 | 13 | |
14 | -if (\PHP_VERSION_ID >= 70300) { |
|
14 | +if ( \PHP_VERSION_ID >= 70300 ) { |
|
15 | 15 | return; |
16 | 16 | } |
17 | 17 | |
18 | -if (!function_exists('is_countable')) { |
|
19 | - function is_countable($value) { return is_array($value) || $value instanceof Countable || $value instanceof ResourceBundle || $value instanceof SimpleXmlElement; } |
|
18 | +if ( ! function_exists( 'is_countable' ) ) { |
|
19 | + function is_countable( $value ) { return is_array( $value ) || $value instanceof Countable || $value instanceof ResourceBundle || $value instanceof SimpleXmlElement; } |
|
20 | 20 | } |
21 | -if (!function_exists('hrtime')) { |
|
22 | - require_once __DIR__.'/Php73.php'; |
|
23 | - p\Php73::$startAt = (int) microtime(true); |
|
24 | - function hrtime($as_number = false) { return p\Php73::hrtime($as_number); } |
|
21 | +if ( ! function_exists( 'hrtime' ) ) { |
|
22 | + require_once __DIR__ . '/Php73.php'; |
|
23 | + p\Php73::$startAt = (int)microtime( true ); |
|
24 | + function hrtime( $as_number = false ) { return p\Php73::hrtime( $as_number ); } |
|
25 | 25 | } |
26 | -if (!function_exists('array_key_first')) { |
|
27 | - function array_key_first(array $array) { foreach ($array as $key => $value) { return $key; } } |
|
26 | +if ( ! function_exists( 'array_key_first' ) ) { |
|
27 | + function array_key_first( array $array ) { foreach ( $array as $key => $value ) { return $key; } } |
|
28 | 28 | } |
29 | -if (!function_exists('array_key_last')) { |
|
30 | - function array_key_last(array $array) { return key(array_slice($array, -1, 1, true)); } |
|
29 | +if ( ! function_exists( 'array_key_last' ) ) { |
|
30 | + function array_key_last( array $array ) { return key( array_slice( $array, -1, 1, true ) ); } |
|
31 | 31 | } |
@@ -26,18 +26,18 @@ |
||
26 | 26 | * |
27 | 27 | * @return array|float|int |
28 | 28 | */ |
29 | - public static function hrtime($asNum = false) |
|
29 | + public static function hrtime( $asNum = false ) |
|
30 | 30 | { |
31 | - $ns = microtime(false); |
|
32 | - $s = substr($ns, 11) - self::$startAt; |
|
33 | - $ns = 1E9 * (float) $ns; |
|
31 | + $ns = microtime( false ); |
|
32 | + $s = substr( $ns, 11 ) - self::$startAt; |
|
33 | + $ns = 1E9 * (float)$ns; |
|
34 | 34 | |
35 | - if ($asNum) { |
|
35 | + if ( $asNum ) { |
|
36 | 36 | $ns += $s * 1E9; |
37 | 37 | |
38 | - return \PHP_INT_SIZE === 4 ? $ns : (int) $ns; |
|
38 | + return \PHP_INT_SIZE === 4 ? $ns : (int)$ns; |
|
39 | 39 | } |
40 | 40 | |
41 | - return [$s, (int) $ns]; |
|
41 | + return [ $s, (int)$ns ]; |
|
42 | 42 | } |
43 | 43 | } |