@@ -64,23 +64,23 @@ class Shell
6464 /** @var resource The actual process resource returned from proc_open */
6565 protected $ process = null ;
6666
67- /** @var array Status of the process as returned from proc_get_status */
68- protected $ processStatus = null ;
69-
7067 /** @var int Process starting time in unix timestamp */
7168 protected $ processStartTime ;
7269
73- /** @var string Current state of the shell execution */
74- protected $ state = self :: STATE_READY ;
70+ /** @var array Status of the process as returned from proc_get_status */
71+ protected $ processStatus = null ;
7572
7673 /** @var float Default timeout for the process in seconds with microseconds */
7774 protected $ processTimeout = null ;
7875
76+ /** @var string Current state of the shell execution, set from this class, NOT for proc_get_status */
77+ protected $ state = self ::STATE_READY ;
78+
7979 public function __construct (string $ command , string $ input = null )
8080 {
8181 // @codeCoverageIgnoreStart
8282 if (!\function_exists ('proc_open ' )) {
83- throw new RuntimeException ('Required proc_open could not be found in your PHP setup ' );
83+ throw new RuntimeException ('Required proc_open could not be found in your PHP setup. ' );
8484 }
8585 // @codeCoverageIgnoreEnd
8686
@@ -90,7 +90,7 @@ public function __construct(string $command, string $input = null)
9090
9191 protected function getDescriptors (): array
9292 {
93- $ out = '\\' === \ DIRECTORY_SEPARATOR ? ['file ' , 'NUL ' , 'w ' ] : ['pipe ' , 'w ' ];
93+ $ out = $ this -> isWindows () ? ['file ' , 'NUL ' , 'w ' ] : ['pipe ' , 'w ' ];
9494
9595 return [
9696 self ::STDIN_DESCRIPTOR_KEY => ['pipe ' , 'r ' ],
@@ -99,6 +99,11 @@ protected function getDescriptors(): array
9999 ];
100100 }
101101
102+ protected function isWindows (): bool
103+ {
104+ return '\\' === \DIRECTORY_SEPARATOR ;
105+ }
106+
102107 protected function setInput ()
103108 {
104109 \fwrite ($ this ->pipes [self ::STDIN_DESCRIPTOR_KEY ], $ this ->input );
@@ -145,7 +150,7 @@ protected function checkTimeout()
145150 if ($ executionDuration > $ this ->processTimeout ) {
146151 $ this ->kill ();
147152
148- throw new RuntimeException ('Process timeout occurred, terminated ' );
153+ throw new RuntimeException ('Timeout occurred, process terminated. ' );
149154 }
150155
151156 // @codeCoverageIgnoreStart
@@ -166,7 +171,7 @@ public function setOptions(string $cwd = null, array $env = null, float $timeout
166171 public function execute (bool $ async = false ): self
167172 {
168173 if ($ this ->isRunning ()) {
169- throw new RuntimeException ('Process is already running ' );
174+ throw new RuntimeException ('Process is already running. ' );
170175 }
171176
172177 $ this ->descriptors = $ this ->getDescriptors ();
@@ -264,6 +269,6 @@ public function kill()
264269 public function __destruct ()
265270 {
266271 // If async (run in background) => we don't care if it ever closes
267- // Otherwise, waited already till it runs or timeout occurs, in which case kill it
272+ // Otherwise, waited already till it ends itself or timeout occurs, in which case kill it
268273 }
269274}
0 commit comments