diff --git a/src/Adapters/Symfony/Component/Process/Process.php b/src/Adapters/Symfony/Component/Process/Process.php index ce3a18790..1ebae185c 100644 --- a/src/Adapters/Symfony/Component/Process/Process.php +++ b/src/Adapters/Symfony/Component/Process/Process.php @@ -3,14 +3,16 @@ namespace lucatume\WPBrowser\Adapters\Symfony\Component\Process; use Symfony\Component\Process\Exception\LogicException; +use Symfony\Component\Process\Pipes\PipesInterface; use Symfony\Component\Process\Process as SymfonyProcess; class Process extends SymfonyProcess { /** - * @var array + * @var bool */ - private $options = []; + private $createNewConsole = false; + /** * @param string[] $command * @param array|null $env @@ -50,28 +52,31 @@ public function getStartTime(): float return $startTime; } - /** - * @param string $name - * @param array $arguments - * @return void - */ - public function __call(string $name, array $arguments) + public function __destruct() { - if ($name === 'setOptions') { - $this->options = $arguments[0] ?? []; + if ($this->createNewConsole) { + $processPipesProperty = new \ReflectionProperty(SymfonyProcess::class, 'processPipes'); + $processPipesProperty->setAccessible(true); + /** @var PipesInterface $processPipes */ + $processPipes = $processPipesProperty->getValue($this); + $processPipes->close(); + + return; } - return; + + $this->stop(0); } - public function __destruct() + public function createNewConsole(): void { - if (($this->options['create_new_console'] ?? false) || method_exists($this, 'setOptions')) { - parent::__destruct(); - return; - } + $this->createNewConsole = true; - $closeMethodReflection = new \ReflectionMethod(SymfonyProcess::class, 'close'); - $closeMethodReflection->setAccessible(true); - $closeMethodReflection->invoke($this); + $optionsReflectionProperty = new \ReflectionProperty(SymfonyProcess::class, 'options'); + $optionsReflectionProperty->setAccessible(true); + $options = $optionsReflectionProperty->getValue($this); + $options = is_array($options) ? $options : []; + $options['create_new_console'] = true; + $options['bypass_shell'] = true; + $optionsReflectionProperty->setValue($this, $options); } } diff --git a/src/ManagedProcess/ChromeDriver.php b/src/ManagedProcess/ChromeDriver.php index 5055b1ceb..e4e174c84 100644 --- a/src/ManagedProcess/ChromeDriver.php +++ b/src/ManagedProcess/ChromeDriver.php @@ -48,7 +48,7 @@ public function doStart(): void { $command = [$this->chromeDriverBinary, '--port=' . $this->port, ...$this->arguments]; $process = new Process($command); - $process->setOptions(['create_new_console' => true]); + $process->createNewConsole(); $process->start(); $this->confirmStart($process); $this->pid = $process->getPid(); diff --git a/src/ManagedProcess/PhpBuiltInServer.php b/src/ManagedProcess/PhpBuiltInServer.php index 516629731..1f24f631c 100644 --- a/src/ManagedProcess/PhpBuiltInServer.php +++ b/src/ManagedProcess/PhpBuiltInServer.php @@ -71,7 +71,7 @@ public function doStart(): void $this->docRoot, $this->env ); - $process->setOptions(['create_new_console' => true]); + $process->createNewConsole(); $process->start(); if (!$this->confirmServerRunningOnPort($process)) { $error = new RuntimeException(