@@ -20,50 +20,50 @@ |
||
20 | 20 | */ |
21 | 21 | class ProcessTimedOutException extends RuntimeException |
22 | 22 | { |
23 | - public const TYPE_GENERAL = 1; |
|
24 | - public const TYPE_IDLE = 2; |
|
23 | + public const TYPE_GENERAL = 1; |
|
24 | + public const TYPE_IDLE = 2; |
|
25 | 25 | |
26 | - private $process; |
|
27 | - private $timeoutType; |
|
26 | + private $process; |
|
27 | + private $timeoutType; |
|
28 | 28 | |
29 | - public function __construct(Process $process, int $timeoutType) |
|
30 | - { |
|
31 | - $this->process = $process; |
|
32 | - $this->timeoutType = $timeoutType; |
|
29 | + public function __construct(Process $process, int $timeoutType) |
|
30 | + { |
|
31 | + $this->process = $process; |
|
32 | + $this->timeoutType = $timeoutType; |
|
33 | 33 | |
34 | - parent::__construct(sprintf( |
|
35 | - 'The process "%s" exceeded the timeout of %s seconds.', |
|
36 | - $process->getCommandLine(), |
|
37 | - $this->getExceededTimeout() |
|
38 | - )); |
|
39 | - } |
|
34 | + parent::__construct(sprintf( |
|
35 | + 'The process "%s" exceeded the timeout of %s seconds.', |
|
36 | + $process->getCommandLine(), |
|
37 | + $this->getExceededTimeout() |
|
38 | + )); |
|
39 | + } |
|
40 | 40 | |
41 | - public function getProcess() |
|
42 | - { |
|
43 | - return $this->process; |
|
44 | - } |
|
41 | + public function getProcess() |
|
42 | + { |
|
43 | + return $this->process; |
|
44 | + } |
|
45 | 45 | |
46 | - public function isGeneralTimeout() |
|
47 | - { |
|
48 | - return self::TYPE_GENERAL === $this->timeoutType; |
|
49 | - } |
|
46 | + public function isGeneralTimeout() |
|
47 | + { |
|
48 | + return self::TYPE_GENERAL === $this->timeoutType; |
|
49 | + } |
|
50 | 50 | |
51 | - public function isIdleTimeout() |
|
52 | - { |
|
53 | - return self::TYPE_IDLE === $this->timeoutType; |
|
54 | - } |
|
51 | + public function isIdleTimeout() |
|
52 | + { |
|
53 | + return self::TYPE_IDLE === $this->timeoutType; |
|
54 | + } |
|
55 | 55 | |
56 | - public function getExceededTimeout() |
|
57 | - { |
|
58 | - switch ($this->timeoutType) { |
|
59 | - case self::TYPE_GENERAL: |
|
60 | - return $this->process->getTimeout(); |
|
56 | + public function getExceededTimeout() |
|
57 | + { |
|
58 | + switch ($this->timeoutType) { |
|
59 | + case self::TYPE_GENERAL: |
|
60 | + return $this->process->getTimeout(); |
|
61 | 61 | |
62 | - case self::TYPE_IDLE: |
|
63 | - return $this->process->getIdleTimeout(); |
|
62 | + case self::TYPE_IDLE: |
|
63 | + return $this->process->getIdleTimeout(); |
|
64 | 64 | |
65 | - default: |
|
66 | - throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType)); |
|
67 | - } |
|
68 | - } |
|
65 | + default: |
|
66 | + throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType)); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | } |
@@ -26,16 +26,16 @@ discard block |
||
26 | 26 | private $process; |
27 | 27 | private $timeoutType; |
28 | 28 | |
29 | - public function __construct(Process $process, int $timeoutType) |
|
29 | + public function __construct( Process $process, int $timeoutType ) |
|
30 | 30 | { |
31 | 31 | $this->process = $process; |
32 | 32 | $this->timeoutType = $timeoutType; |
33 | 33 | |
34 | - parent::__construct(sprintf( |
|
34 | + parent::__construct( sprintf( |
|
35 | 35 | 'The process "%s" exceeded the timeout of %s seconds.', |
36 | 36 | $process->getCommandLine(), |
37 | 37 | $this->getExceededTimeout() |
38 | - )); |
|
38 | + ) ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | public function getProcess() |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | public function getExceededTimeout() |
57 | 57 | { |
58 | - switch ($this->timeoutType) { |
|
58 | + switch ( $this->timeoutType ) { |
|
59 | 59 | case self::TYPE_GENERAL: |
60 | 60 | return $this->process->getTimeout(); |
61 | 61 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | return $this->process->getIdleTimeout(); |
64 | 64 | |
65 | 65 | default: |
66 | - throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType)); |
|
66 | + throw new \LogicException( sprintf( 'Unknown timeout type "%d".', $this->timeoutType ) ); |
|
67 | 67 | } |
68 | 68 | } |
69 | 69 | } |
@@ -18,16 +18,14 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @author Johannes M. Schmitt <[email protected]> |
20 | 20 | */ |
21 | -class ProcessTimedOutException extends RuntimeException |
|
22 | -{ |
|
21 | +class ProcessTimedOutException extends RuntimeException { |
|
23 | 22 | public const TYPE_GENERAL = 1; |
24 | 23 | public const TYPE_IDLE = 2; |
25 | 24 | |
26 | 25 | private $process; |
27 | 26 | private $timeoutType; |
28 | 27 | |
29 | - public function __construct(Process $process, int $timeoutType) |
|
30 | - { |
|
28 | + public function __construct(Process $process, int $timeoutType) { |
|
31 | 29 | $this->process = $process; |
32 | 30 | $this->timeoutType = $timeoutType; |
33 | 31 | |
@@ -38,23 +36,19 @@ discard block |
||
38 | 36 | )); |
39 | 37 | } |
40 | 38 | |
41 | - public function getProcess() |
|
42 | - { |
|
39 | + public function getProcess() { |
|
43 | 40 | return $this->process; |
44 | 41 | } |
45 | 42 | |
46 | - public function isGeneralTimeout() |
|
47 | - { |
|
43 | + public function isGeneralTimeout() { |
|
48 | 44 | return self::TYPE_GENERAL === $this->timeoutType; |
49 | 45 | } |
50 | 46 | |
51 | - public function isIdleTimeout() |
|
52 | - { |
|
47 | + public function isIdleTimeout() { |
|
53 | 48 | return self::TYPE_IDLE === $this->timeoutType; |
54 | 49 | } |
55 | 50 | |
56 | - public function getExceededTimeout() |
|
57 | - { |
|
51 | + public function getExceededTimeout() { |
|
58 | 52 | switch ($this->timeoutType) { |
59 | 53 | case self::TYPE_GENERAL: |
60 | 54 | return $this->process->getTimeout(); |
@@ -16,6 +16,5 @@ |
||
16 | 16 | * |
17 | 17 | * @author Romain Neutron <[email protected]> |
18 | 18 | */ |
19 | -class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface |
|
20 | -{ |
|
19 | +class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface { |
|
21 | 20 | } |
@@ -16,6 +16,5 @@ |
||
16 | 16 | * |
17 | 17 | * @author Johannes M. Schmitt <[email protected]> |
18 | 18 | */ |
19 | -interface ExceptionInterface extends \Throwable |
|
20 | -{ |
|
19 | +interface ExceptionInterface extends \Throwable { |
|
21 | 20 | } |
@@ -20,35 +20,35 @@ |
||
20 | 20 | */ |
21 | 21 | class ProcessFailedException extends RuntimeException |
22 | 22 | { |
23 | - private $process; |
|
24 | - |
|
25 | - public function __construct(Process $process) |
|
26 | - { |
|
27 | - if ($process->isSuccessful()) { |
|
28 | - throw new InvalidArgumentException('Expected a failed process, but the given process was successful.'); |
|
29 | - } |
|
30 | - |
|
31 | - $error = sprintf('The command "%s" failed.'."\n\nExit Code: %s(%s)\n\nWorking directory: %s", |
|
32 | - $process->getCommandLine(), |
|
33 | - $process->getExitCode(), |
|
34 | - $process->getExitCodeText(), |
|
35 | - $process->getWorkingDirectory() |
|
36 | - ); |
|
37 | - |
|
38 | - if (!$process->isOutputDisabled()) { |
|
39 | - $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s", |
|
40 | - $process->getOutput(), |
|
41 | - $process->getErrorOutput() |
|
42 | - ); |
|
43 | - } |
|
44 | - |
|
45 | - parent::__construct($error); |
|
46 | - |
|
47 | - $this->process = $process; |
|
48 | - } |
|
49 | - |
|
50 | - public function getProcess() |
|
51 | - { |
|
52 | - return $this->process; |
|
53 | - } |
|
23 | + private $process; |
|
24 | + |
|
25 | + public function __construct(Process $process) |
|
26 | + { |
|
27 | + if ($process->isSuccessful()) { |
|
28 | + throw new InvalidArgumentException('Expected a failed process, but the given process was successful.'); |
|
29 | + } |
|
30 | + |
|
31 | + $error = sprintf('The command "%s" failed.'."\n\nExit Code: %s(%s)\n\nWorking directory: %s", |
|
32 | + $process->getCommandLine(), |
|
33 | + $process->getExitCode(), |
|
34 | + $process->getExitCodeText(), |
|
35 | + $process->getWorkingDirectory() |
|
36 | + ); |
|
37 | + |
|
38 | + if (!$process->isOutputDisabled()) { |
|
39 | + $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s", |
|
40 | + $process->getOutput(), |
|
41 | + $process->getErrorOutput() |
|
42 | + ); |
|
43 | + } |
|
44 | + |
|
45 | + parent::__construct($error); |
|
46 | + |
|
47 | + $this->process = $process; |
|
48 | + } |
|
49 | + |
|
50 | + public function getProcess() |
|
51 | + { |
|
52 | + return $this->process; |
|
53 | + } |
|
54 | 54 | } |
@@ -22,27 +22,27 @@ |
||
22 | 22 | { |
23 | 23 | private $process; |
24 | 24 | |
25 | - public function __construct(Process $process) |
|
25 | + public function __construct( Process $process ) |
|
26 | 26 | { |
27 | - if ($process->isSuccessful()) { |
|
28 | - throw new InvalidArgumentException('Expected a failed process, but the given process was successful.'); |
|
27 | + if ( $process->isSuccessful() ) { |
|
28 | + throw new InvalidArgumentException( 'Expected a failed process, but the given process was successful.' ); |
|
29 | 29 | } |
30 | 30 | |
31 | - $error = sprintf('The command "%s" failed.'."\n\nExit Code: %s(%s)\n\nWorking directory: %s", |
|
31 | + $error = sprintf( 'The command "%s" failed.' . "\n\nExit Code: %s(%s)\n\nWorking directory: %s", |
|
32 | 32 | $process->getCommandLine(), |
33 | 33 | $process->getExitCode(), |
34 | 34 | $process->getExitCodeText(), |
35 | 35 | $process->getWorkingDirectory() |
36 | 36 | ); |
37 | 37 | |
38 | - if (!$process->isOutputDisabled()) { |
|
39 | - $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s", |
|
38 | + if ( ! $process->isOutputDisabled() ) { |
|
39 | + $error .= sprintf( "\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s", |
|
40 | 40 | $process->getOutput(), |
41 | 41 | $process->getErrorOutput() |
42 | 42 | ); |
43 | 43 | } |
44 | 44 | |
45 | - parent::__construct($error); |
|
45 | + parent::__construct( $error ); |
|
46 | 46 | |
47 | 47 | $this->process = $process; |
48 | 48 | } |
@@ -18,12 +18,10 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @author Johannes M. Schmitt <[email protected]> |
20 | 20 | */ |
21 | -class ProcessFailedException extends RuntimeException |
|
22 | -{ |
|
21 | +class ProcessFailedException extends RuntimeException { |
|
23 | 22 | private $process; |
24 | 23 | |
25 | - public function __construct(Process $process) |
|
26 | - { |
|
24 | + public function __construct(Process $process) { |
|
27 | 25 | if ($process->isSuccessful()) { |
28 | 26 | throw new InvalidArgumentException('Expected a failed process, but the given process was successful.'); |
29 | 27 | } |
@@ -47,8 +45,7 @@ discard block |
||
47 | 45 | $this->process = $process; |
48 | 46 | } |
49 | 47 | |
50 | - public function getProcess() |
|
51 | - { |
|
48 | + public function getProcess() { |
|
52 | 49 | return $this->process; |
53 | 50 | } |
54 | 51 | } |
@@ -16,6 +16,5 @@ |
||
16 | 16 | * |
17 | 17 | * @author Johannes M. Schmitt <[email protected]> |
18 | 18 | */ |
19 | -class RuntimeException extends \RuntimeException implements ExceptionInterface |
|
20 | -{ |
|
19 | +class RuntimeException extends \RuntimeException implements ExceptionInterface { |
|
21 | 20 | } |
@@ -20,22 +20,22 @@ |
||
20 | 20 | */ |
21 | 21 | final class ProcessSignaledException extends RuntimeException |
22 | 22 | { |
23 | - private $process; |
|
23 | + private $process; |
|
24 | 24 | |
25 | - public function __construct(Process $process) |
|
26 | - { |
|
27 | - $this->process = $process; |
|
25 | + public function __construct(Process $process) |
|
26 | + { |
|
27 | + $this->process = $process; |
|
28 | 28 | |
29 | - parent::__construct(sprintf('The process has been signaled with signal "%s".', $process->getTermSignal())); |
|
30 | - } |
|
29 | + parent::__construct(sprintf('The process has been signaled with signal "%s".', $process->getTermSignal())); |
|
30 | + } |
|
31 | 31 | |
32 | - public function getProcess(): Process |
|
33 | - { |
|
34 | - return $this->process; |
|
35 | - } |
|
32 | + public function getProcess(): Process |
|
33 | + { |
|
34 | + return $this->process; |
|
35 | + } |
|
36 | 36 | |
37 | - public function getSignal(): int |
|
38 | - { |
|
39 | - return $this->getProcess()->getTermSignal(); |
|
40 | - } |
|
37 | + public function getSignal(): int |
|
38 | + { |
|
39 | + return $this->getProcess()->getTermSignal(); |
|
40 | + } |
|
41 | 41 | } |
@@ -22,11 +22,11 @@ |
||
22 | 22 | { |
23 | 23 | private $process; |
24 | 24 | |
25 | - public function __construct(Process $process) |
|
25 | + public function __construct( Process $process ) |
|
26 | 26 | { |
27 | 27 | $this->process = $process; |
28 | 28 | |
29 | - parent::__construct(sprintf('The process has been signaled with signal "%s".', $process->getTermSignal())); |
|
29 | + parent::__construct( sprintf( 'The process has been signaled with signal "%s".', $process->getTermSignal() ) ); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | public function getProcess(): Process |
@@ -18,12 +18,10 @@ |
||
18 | 18 | * |
19 | 19 | * @author Sullivan Senechal <[email protected]> |
20 | 20 | */ |
21 | -final class ProcessSignaledException extends RuntimeException |
|
22 | -{ |
|
21 | +final class ProcessSignaledException extends RuntimeException { |
|
23 | 22 | private $process; |
24 | 23 | |
25 | - public function __construct(Process $process) |
|
26 | - { |
|
24 | + public function __construct(Process $process) { |
|
27 | 25 | $this->process = $process; |
28 | 26 | |
29 | 27 | parent::__construct(sprintf('The process has been signaled with signal "%s".', $process->getTermSignal())); |
@@ -16,6 +16,5 @@ |
||
16 | 16 | * |
17 | 17 | * @author Romain Neutron <[email protected]> |
18 | 18 | */ |
19 | -class LogicException extends \LogicException implements ExceptionInterface |
|
20 | -{ |
|
19 | +class LogicException extends \LogicException implements ExceptionInterface { |
|
21 | 20 | } |
@@ -20,42 +20,42 @@ |
||
20 | 20 | */ |
21 | 21 | interface PipesInterface |
22 | 22 | { |
23 | - public const CHUNK_SIZE = 16384; |
|
24 | - |
|
25 | - /** |
|
26 | - * Returns an array of descriptors for the use of proc_open. |
|
27 | - */ |
|
28 | - public function getDescriptors(): array; |
|
29 | - |
|
30 | - /** |
|
31 | - * Returns an array of filenames indexed by their related stream in case these pipes use temporary files. |
|
32 | - * |
|
33 | - * @return string[] |
|
34 | - */ |
|
35 | - public function getFiles(): array; |
|
36 | - |
|
37 | - /** |
|
38 | - * Reads data in file handles and pipes. |
|
39 | - * |
|
40 | - * @param bool $blocking Whether to use blocking calls or not |
|
41 | - * @param bool $close Whether to close pipes if they've reached EOF |
|
42 | - * |
|
43 | - * @return string[] An array of read data indexed by their fd |
|
44 | - */ |
|
45 | - public function readAndWrite(bool $blocking, bool $close = false): array; |
|
46 | - |
|
47 | - /** |
|
48 | - * Returns if the current state has open file handles or pipes. |
|
49 | - */ |
|
50 | - public function areOpen(): bool; |
|
51 | - |
|
52 | - /** |
|
53 | - * Returns if pipes are able to read output. |
|
54 | - */ |
|
55 | - public function haveReadSupport(): bool; |
|
56 | - |
|
57 | - /** |
|
58 | - * Closes file handles and pipes. |
|
59 | - */ |
|
60 | - public function close(); |
|
23 | + public const CHUNK_SIZE = 16384; |
|
24 | + |
|
25 | + /** |
|
26 | + * Returns an array of descriptors for the use of proc_open. |
|
27 | + */ |
|
28 | + public function getDescriptors(): array; |
|
29 | + |
|
30 | + /** |
|
31 | + * Returns an array of filenames indexed by their related stream in case these pipes use temporary files. |
|
32 | + * |
|
33 | + * @return string[] |
|
34 | + */ |
|
35 | + public function getFiles(): array; |
|
36 | + |
|
37 | + /** |
|
38 | + * Reads data in file handles and pipes. |
|
39 | + * |
|
40 | + * @param bool $blocking Whether to use blocking calls or not |
|
41 | + * @param bool $close Whether to close pipes if they've reached EOF |
|
42 | + * |
|
43 | + * @return string[] An array of read data indexed by their fd |
|
44 | + */ |
|
45 | + public function readAndWrite(bool $blocking, bool $close = false): array; |
|
46 | + |
|
47 | + /** |
|
48 | + * Returns if the current state has open file handles or pipes. |
|
49 | + */ |
|
50 | + public function areOpen(): bool; |
|
51 | + |
|
52 | + /** |
|
53 | + * Returns if pipes are able to read output. |
|
54 | + */ |
|
55 | + public function haveReadSupport(): bool; |
|
56 | + |
|
57 | + /** |
|
58 | + * Closes file handles and pipes. |
|
59 | + */ |
|
60 | + public function close(); |
|
61 | 61 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | * |
43 | 43 | * @return string[] An array of read data indexed by their fd |
44 | 44 | */ |
45 | - public function readAndWrite(bool $blocking, bool $close = false): array; |
|
45 | + public function readAndWrite( bool $blocking, bool $close = false ): array; |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Returns if the current state has open file handles or pipes. |
@@ -18,8 +18,7 @@ |
||
18 | 18 | * |
19 | 19 | * @internal |
20 | 20 | */ |
21 | -interface PipesInterface |
|
22 | -{ |
|
21 | +interface PipesInterface { |
|
23 | 22 | public const CHUNK_SIZE = 16384; |
24 | 23 | |
25 | 24 | /** |
@@ -18,8 +18,7 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @internal |
20 | 20 | */ |
21 | -abstract class AbstractPipes implements PipesInterface |
|
22 | -{ |
|
21 | +abstract class AbstractPipes implements PipesInterface { |
|
23 | 22 | public $pipes = []; |
24 | 23 | |
25 | 24 | private $inputBuffer = ''; |
@@ -30,8 +29,7 @@ discard block |
||
30 | 29 | /** |
31 | 30 | * @param resource|string|int|float|bool|\Iterator|null $input |
32 | 31 | */ |
33 | - public function __construct($input) |
|
34 | - { |
|
32 | + public function __construct($input) { |
|
35 | 33 | if (\is_resource($input) || $input instanceof \Iterator) { |
36 | 34 | $this->input = $input; |
37 | 35 | } elseif (\is_string($input)) { |
@@ -44,8 +42,7 @@ discard block |
||
44 | 42 | /** |
45 | 43 | * {@inheritdoc} |
46 | 44 | */ |
47 | - public function close() |
|
48 | - { |
|
45 | + public function close() { |
|
49 | 46 | foreach ($this->pipes as $pipe) { |
50 | 47 | fclose($pipe); |
51 | 48 | } |
@@ -67,8 +64,7 @@ discard block |
||
67 | 64 | /** |
68 | 65 | * Unblocks streams. |
69 | 66 | */ |
70 | - protected function unblock() |
|
71 | - { |
|
67 | + protected function unblock() { |
|
72 | 68 | if (!$this->blocked) { |
73 | 69 | return; |
74 | 70 | } |
@@ -171,8 +167,7 @@ discard block |
||
171 | 167 | /** |
172 | 168 | * @internal |
173 | 169 | */ |
174 | - public function handleError(int $type, string $msg) |
|
175 | - { |
|
170 | + public function handleError(int $type, string $msg) { |
|
176 | 171 | $this->lastError = $msg; |
177 | 172 | } |
178 | 173 | } |
@@ -20,159 +20,159 @@ |
||
20 | 20 | */ |
21 | 21 | abstract class AbstractPipes implements PipesInterface |
22 | 22 | { |
23 | - public $pipes = []; |
|
24 | - |
|
25 | - private $inputBuffer = ''; |
|
26 | - private $input; |
|
27 | - private $blocked = true; |
|
28 | - private $lastError; |
|
29 | - |
|
30 | - /** |
|
31 | - * @param resource|string|int|float|bool|\Iterator|null $input |
|
32 | - */ |
|
33 | - public function __construct($input) |
|
34 | - { |
|
35 | - if (\is_resource($input) || $input instanceof \Iterator) { |
|
36 | - $this->input = $input; |
|
37 | - } elseif (\is_string($input)) { |
|
38 | - $this->inputBuffer = $input; |
|
39 | - } else { |
|
40 | - $this->inputBuffer = (string) $input; |
|
41 | - } |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * {@inheritdoc} |
|
46 | - */ |
|
47 | - public function close() |
|
48 | - { |
|
49 | - foreach ($this->pipes as $pipe) { |
|
50 | - fclose($pipe); |
|
51 | - } |
|
52 | - $this->pipes = []; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Returns true if a system call has been interrupted. |
|
57 | - */ |
|
58 | - protected function hasSystemCallBeenInterrupted(): bool |
|
59 | - { |
|
60 | - $lastError = $this->lastError; |
|
61 | - $this->lastError = null; |
|
62 | - |
|
63 | - // stream_select returns false when the `select` system call is interrupted by an incoming signal |
|
64 | - return null !== $lastError && false !== stripos($lastError, 'interrupted system call'); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Unblocks streams. |
|
69 | - */ |
|
70 | - protected function unblock() |
|
71 | - { |
|
72 | - if (!$this->blocked) { |
|
73 | - return; |
|
74 | - } |
|
75 | - |
|
76 | - foreach ($this->pipes as $pipe) { |
|
77 | - stream_set_blocking($pipe, 0); |
|
78 | - } |
|
79 | - if (\is_resource($this->input)) { |
|
80 | - stream_set_blocking($this->input, 0); |
|
81 | - } |
|
82 | - |
|
83 | - $this->blocked = false; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Writes input to stdin. |
|
88 | - * |
|
89 | - * @throws InvalidArgumentException When an input iterator yields a non supported value |
|
90 | - */ |
|
91 | - protected function write(): ?array |
|
92 | - { |
|
93 | - if (!isset($this->pipes[0])) { |
|
94 | - return null; |
|
95 | - } |
|
96 | - $input = $this->input; |
|
97 | - |
|
98 | - if ($input instanceof \Iterator) { |
|
99 | - if (!$input->valid()) { |
|
100 | - $input = null; |
|
101 | - } elseif (\is_resource($input = $input->current())) { |
|
102 | - stream_set_blocking($input, 0); |
|
103 | - } elseif (!isset($this->inputBuffer[0])) { |
|
104 | - if (!\is_string($input)) { |
|
105 | - if (!is_scalar($input)) { |
|
106 | - throw new InvalidArgumentException(sprintf('"%s" yielded a value of type "%s", but only scalars and stream resources are supported.', \get_class($this->input), \gettype($input))); |
|
107 | - } |
|
108 | - $input = (string) $input; |
|
109 | - } |
|
110 | - $this->inputBuffer = $input; |
|
111 | - $this->input->next(); |
|
112 | - $input = null; |
|
113 | - } else { |
|
114 | - $input = null; |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - $r = $e = []; |
|
119 | - $w = [$this->pipes[0]]; |
|
120 | - |
|
121 | - // let's have a look if something changed in streams |
|
122 | - if (false === @stream_select($r, $w, $e, 0, 0)) { |
|
123 | - return null; |
|
124 | - } |
|
125 | - |
|
126 | - foreach ($w as $stdin) { |
|
127 | - if (isset($this->inputBuffer[0])) { |
|
128 | - $written = fwrite($stdin, $this->inputBuffer); |
|
129 | - $this->inputBuffer = substr($this->inputBuffer, $written); |
|
130 | - if (isset($this->inputBuffer[0])) { |
|
131 | - return [$this->pipes[0]]; |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - if ($input) { |
|
136 | - for (;;) { |
|
137 | - $data = fread($input, self::CHUNK_SIZE); |
|
138 | - if (!isset($data[0])) { |
|
139 | - break; |
|
140 | - } |
|
141 | - $written = fwrite($stdin, $data); |
|
142 | - $data = substr($data, $written); |
|
143 | - if (isset($data[0])) { |
|
144 | - $this->inputBuffer = $data; |
|
145 | - |
|
146 | - return [$this->pipes[0]]; |
|
147 | - } |
|
148 | - } |
|
149 | - if (feof($input)) { |
|
150 | - if ($this->input instanceof \Iterator) { |
|
151 | - $this->input->next(); |
|
152 | - } else { |
|
153 | - $this->input = null; |
|
154 | - } |
|
155 | - } |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - // no input to read on resource, buffer is empty |
|
160 | - if (!isset($this->inputBuffer[0]) && !($this->input instanceof \Iterator ? $this->input->valid() : $this->input)) { |
|
161 | - $this->input = null; |
|
162 | - fclose($this->pipes[0]); |
|
163 | - unset($this->pipes[0]); |
|
164 | - } elseif (!$w) { |
|
165 | - return [$this->pipes[0]]; |
|
166 | - } |
|
167 | - |
|
168 | - return null; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @internal |
|
173 | - */ |
|
174 | - public function handleError(int $type, string $msg) |
|
175 | - { |
|
176 | - $this->lastError = $msg; |
|
177 | - } |
|
23 | + public $pipes = []; |
|
24 | + |
|
25 | + private $inputBuffer = ''; |
|
26 | + private $input; |
|
27 | + private $blocked = true; |
|
28 | + private $lastError; |
|
29 | + |
|
30 | + /** |
|
31 | + * @param resource|string|int|float|bool|\Iterator|null $input |
|
32 | + */ |
|
33 | + public function __construct($input) |
|
34 | + { |
|
35 | + if (\is_resource($input) || $input instanceof \Iterator) { |
|
36 | + $this->input = $input; |
|
37 | + } elseif (\is_string($input)) { |
|
38 | + $this->inputBuffer = $input; |
|
39 | + } else { |
|
40 | + $this->inputBuffer = (string) $input; |
|
41 | + } |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * {@inheritdoc} |
|
46 | + */ |
|
47 | + public function close() |
|
48 | + { |
|
49 | + foreach ($this->pipes as $pipe) { |
|
50 | + fclose($pipe); |
|
51 | + } |
|
52 | + $this->pipes = []; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Returns true if a system call has been interrupted. |
|
57 | + */ |
|
58 | + protected function hasSystemCallBeenInterrupted(): bool |
|
59 | + { |
|
60 | + $lastError = $this->lastError; |
|
61 | + $this->lastError = null; |
|
62 | + |
|
63 | + // stream_select returns false when the `select` system call is interrupted by an incoming signal |
|
64 | + return null !== $lastError && false !== stripos($lastError, 'interrupted system call'); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Unblocks streams. |
|
69 | + */ |
|
70 | + protected function unblock() |
|
71 | + { |
|
72 | + if (!$this->blocked) { |
|
73 | + return; |
|
74 | + } |
|
75 | + |
|
76 | + foreach ($this->pipes as $pipe) { |
|
77 | + stream_set_blocking($pipe, 0); |
|
78 | + } |
|
79 | + if (\is_resource($this->input)) { |
|
80 | + stream_set_blocking($this->input, 0); |
|
81 | + } |
|
82 | + |
|
83 | + $this->blocked = false; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Writes input to stdin. |
|
88 | + * |
|
89 | + * @throws InvalidArgumentException When an input iterator yields a non supported value |
|
90 | + */ |
|
91 | + protected function write(): ?array |
|
92 | + { |
|
93 | + if (!isset($this->pipes[0])) { |
|
94 | + return null; |
|
95 | + } |
|
96 | + $input = $this->input; |
|
97 | + |
|
98 | + if ($input instanceof \Iterator) { |
|
99 | + if (!$input->valid()) { |
|
100 | + $input = null; |
|
101 | + } elseif (\is_resource($input = $input->current())) { |
|
102 | + stream_set_blocking($input, 0); |
|
103 | + } elseif (!isset($this->inputBuffer[0])) { |
|
104 | + if (!\is_string($input)) { |
|
105 | + if (!is_scalar($input)) { |
|
106 | + throw new InvalidArgumentException(sprintf('"%s" yielded a value of type "%s", but only scalars and stream resources are supported.', \get_class($this->input), \gettype($input))); |
|
107 | + } |
|
108 | + $input = (string) $input; |
|
109 | + } |
|
110 | + $this->inputBuffer = $input; |
|
111 | + $this->input->next(); |
|
112 | + $input = null; |
|
113 | + } else { |
|
114 | + $input = null; |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + $r = $e = []; |
|
119 | + $w = [$this->pipes[0]]; |
|
120 | + |
|
121 | + // let's have a look if something changed in streams |
|
122 | + if (false === @stream_select($r, $w, $e, 0, 0)) { |
|
123 | + return null; |
|
124 | + } |
|
125 | + |
|
126 | + foreach ($w as $stdin) { |
|
127 | + if (isset($this->inputBuffer[0])) { |
|
128 | + $written = fwrite($stdin, $this->inputBuffer); |
|
129 | + $this->inputBuffer = substr($this->inputBuffer, $written); |
|
130 | + if (isset($this->inputBuffer[0])) { |
|
131 | + return [$this->pipes[0]]; |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + if ($input) { |
|
136 | + for (;;) { |
|
137 | + $data = fread($input, self::CHUNK_SIZE); |
|
138 | + if (!isset($data[0])) { |
|
139 | + break; |
|
140 | + } |
|
141 | + $written = fwrite($stdin, $data); |
|
142 | + $data = substr($data, $written); |
|
143 | + if (isset($data[0])) { |
|
144 | + $this->inputBuffer = $data; |
|
145 | + |
|
146 | + return [$this->pipes[0]]; |
|
147 | + } |
|
148 | + } |
|
149 | + if (feof($input)) { |
|
150 | + if ($this->input instanceof \Iterator) { |
|
151 | + $this->input->next(); |
|
152 | + } else { |
|
153 | + $this->input = null; |
|
154 | + } |
|
155 | + } |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + // no input to read on resource, buffer is empty |
|
160 | + if (!isset($this->inputBuffer[0]) && !($this->input instanceof \Iterator ? $this->input->valid() : $this->input)) { |
|
161 | + $this->input = null; |
|
162 | + fclose($this->pipes[0]); |
|
163 | + unset($this->pipes[0]); |
|
164 | + } elseif (!$w) { |
|
165 | + return [$this->pipes[0]]; |
|
166 | + } |
|
167 | + |
|
168 | + return null; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @internal |
|
173 | + */ |
|
174 | + public function handleError(int $type, string $msg) |
|
175 | + { |
|
176 | + $this->lastError = $msg; |
|
177 | + } |
|
178 | 178 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | */ |
21 | 21 | abstract class AbstractPipes implements PipesInterface |
22 | 22 | { |
23 | - public $pipes = []; |
|
23 | + public $pipes = [ ]; |
|
24 | 24 | |
25 | 25 | private $inputBuffer = ''; |
26 | 26 | private $input; |
@@ -30,14 +30,14 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * @param resource|string|int|float|bool|\Iterator|null $input |
32 | 32 | */ |
33 | - public function __construct($input) |
|
33 | + public function __construct( $input ) |
|
34 | 34 | { |
35 | - if (\is_resource($input) || $input instanceof \Iterator) { |
|
35 | + if ( \is_resource( $input ) || $input instanceof \Iterator ) { |
|
36 | 36 | $this->input = $input; |
37 | - } elseif (\is_string($input)) { |
|
37 | + } elseif ( \is_string( $input ) ) { |
|
38 | 38 | $this->inputBuffer = $input; |
39 | 39 | } else { |
40 | - $this->inputBuffer = (string) $input; |
|
40 | + $this->inputBuffer = (string)$input; |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function close() |
48 | 48 | { |
49 | - foreach ($this->pipes as $pipe) { |
|
50 | - fclose($pipe); |
|
49 | + foreach ( $this->pipes as $pipe ) { |
|
50 | + fclose( $pipe ); |
|
51 | 51 | } |
52 | - $this->pipes = []; |
|
52 | + $this->pipes = [ ]; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $this->lastError = null; |
62 | 62 | |
63 | 63 | // stream_select returns false when the `select` system call is interrupted by an incoming signal |
64 | - return null !== $lastError && false !== stripos($lastError, 'interrupted system call'); |
|
64 | + return null !== $lastError && false !== stripos( $lastError, 'interrupted system call' ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -69,15 +69,15 @@ discard block |
||
69 | 69 | */ |
70 | 70 | protected function unblock() |
71 | 71 | { |
72 | - if (!$this->blocked) { |
|
72 | + if ( ! $this->blocked ) { |
|
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
76 | - foreach ($this->pipes as $pipe) { |
|
77 | - stream_set_blocking($pipe, 0); |
|
76 | + foreach ( $this->pipes as $pipe ) { |
|
77 | + stream_set_blocking( $pipe, 0 ); |
|
78 | 78 | } |
79 | - if (\is_resource($this->input)) { |
|
80 | - stream_set_blocking($this->input, 0); |
|
79 | + if ( \is_resource( $this->input ) ) { |
|
80 | + stream_set_blocking( $this->input, 0 ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | $this->blocked = false; |
@@ -90,22 +90,22 @@ discard block |
||
90 | 90 | */ |
91 | 91 | protected function write(): ?array |
92 | 92 | { |
93 | - if (!isset($this->pipes[0])) { |
|
93 | + if ( ! isset( $this->pipes[ 0 ] ) ) { |
|
94 | 94 | return null; |
95 | 95 | } |
96 | 96 | $input = $this->input; |
97 | 97 | |
98 | - if ($input instanceof \Iterator) { |
|
99 | - if (!$input->valid()) { |
|
98 | + if ( $input instanceof \Iterator ) { |
|
99 | + if ( ! $input->valid() ) { |
|
100 | 100 | $input = null; |
101 | - } elseif (\is_resource($input = $input->current())) { |
|
102 | - stream_set_blocking($input, 0); |
|
103 | - } elseif (!isset($this->inputBuffer[0])) { |
|
104 | - if (!\is_string($input)) { |
|
105 | - if (!is_scalar($input)) { |
|
106 | - throw new InvalidArgumentException(sprintf('"%s" yielded a value of type "%s", but only scalars and stream resources are supported.', \get_class($this->input), \gettype($input))); |
|
101 | + } elseif ( \is_resource( $input = $input->current() ) ) { |
|
102 | + stream_set_blocking( $input, 0 ); |
|
103 | + } elseif ( ! isset( $this->inputBuffer[ 0 ] ) ) { |
|
104 | + if ( ! \is_string( $input ) ) { |
|
105 | + if ( ! is_scalar( $input ) ) { |
|
106 | + throw new InvalidArgumentException( sprintf( '"%s" yielded a value of type "%s", but only scalars and stream resources are supported.', \get_class( $this->input ), \gettype( $input ) ) ); |
|
107 | 107 | } |
108 | - $input = (string) $input; |
|
108 | + $input = (string)$input; |
|
109 | 109 | } |
110 | 110 | $this->inputBuffer = $input; |
111 | 111 | $this->input->next(); |
@@ -115,39 +115,39 @@ discard block |
||
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
118 | - $r = $e = []; |
|
119 | - $w = [$this->pipes[0]]; |
|
118 | + $r = $e = [ ]; |
|
119 | + $w = [ $this->pipes[ 0 ] ]; |
|
120 | 120 | |
121 | 121 | // let's have a look if something changed in streams |
122 | - if (false === @stream_select($r, $w, $e, 0, 0)) { |
|
122 | + if ( false === @stream_select( $r, $w, $e, 0, 0 ) ) { |
|
123 | 123 | return null; |
124 | 124 | } |
125 | 125 | |
126 | - foreach ($w as $stdin) { |
|
127 | - if (isset($this->inputBuffer[0])) { |
|
128 | - $written = fwrite($stdin, $this->inputBuffer); |
|
129 | - $this->inputBuffer = substr($this->inputBuffer, $written); |
|
130 | - if (isset($this->inputBuffer[0])) { |
|
131 | - return [$this->pipes[0]]; |
|
126 | + foreach ( $w as $stdin ) { |
|
127 | + if ( isset( $this->inputBuffer[ 0 ] ) ) { |
|
128 | + $written = fwrite( $stdin, $this->inputBuffer ); |
|
129 | + $this->inputBuffer = substr( $this->inputBuffer, $written ); |
|
130 | + if ( isset( $this->inputBuffer[ 0 ] ) ) { |
|
131 | + return [ $this->pipes[ 0 ] ]; |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
135 | - if ($input) { |
|
136 | - for (;;) { |
|
137 | - $data = fread($input, self::CHUNK_SIZE); |
|
138 | - if (!isset($data[0])) { |
|
135 | + if ( $input ) { |
|
136 | + for ( ;; ) { |
|
137 | + $data = fread( $input, self::CHUNK_SIZE ); |
|
138 | + if ( ! isset( $data[ 0 ] ) ) { |
|
139 | 139 | break; |
140 | 140 | } |
141 | - $written = fwrite($stdin, $data); |
|
142 | - $data = substr($data, $written); |
|
143 | - if (isset($data[0])) { |
|
141 | + $written = fwrite( $stdin, $data ); |
|
142 | + $data = substr( $data, $written ); |
|
143 | + if ( isset( $data[ 0 ] ) ) { |
|
144 | 144 | $this->inputBuffer = $data; |
145 | 145 | |
146 | - return [$this->pipes[0]]; |
|
146 | + return [ $this->pipes[ 0 ] ]; |
|
147 | 147 | } |
148 | 148 | } |
149 | - if (feof($input)) { |
|
150 | - if ($this->input instanceof \Iterator) { |
|
149 | + if ( feof( $input ) ) { |
|
150 | + if ( $this->input instanceof \Iterator ) { |
|
151 | 151 | $this->input->next(); |
152 | 152 | } else { |
153 | 153 | $this->input = null; |
@@ -157,12 +157,12 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | // no input to read on resource, buffer is empty |
160 | - if (!isset($this->inputBuffer[0]) && !($this->input instanceof \Iterator ? $this->input->valid() : $this->input)) { |
|
160 | + if ( ! isset( $this->inputBuffer[ 0 ] ) && ! ( $this->input instanceof \Iterator ? $this->input->valid() : $this->input ) ) { |
|
161 | 161 | $this->input = null; |
162 | - fclose($this->pipes[0]); |
|
163 | - unset($this->pipes[0]); |
|
164 | - } elseif (!$w) { |
|
165 | - return [$this->pipes[0]]; |
|
162 | + fclose( $this->pipes[ 0 ] ); |
|
163 | + unset( $this->pipes[ 0 ] ); |
|
164 | + } elseif ( ! $w ) { |
|
165 | + return [ $this->pipes[ 0 ] ]; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | return null; |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | /** |
172 | 172 | * @internal |
173 | 173 | */ |
174 | - public function handleError(int $type, string $msg) |
|
174 | + public function handleError( int $type, string $msg ) |
|
175 | 175 | { |
176 | 176 | $this->lastError = $msg; |
177 | 177 | } |