Skip to content

Commit

Permalink
Issue hechoendrupal#4330: Replace ProcessBuilder class with Process i…
Browse files Browse the repository at this point in the history
…n server command.
  • Loading branch information
LOBsTerr committed Sep 15, 2022
1 parent fb8f4eb commit 566474a
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/Command/ServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Process\ProcessBuilder;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\PhpExecutableFinder;
use Drupal\Console\Core\Command\Command;
use Drupal\Console\Core\Utils\ConfigurationManager;
Expand All @@ -22,6 +22,7 @@
*/
class ServerCommand extends Command
{

/**
* @var string
*/
Expand All @@ -40,7 +41,7 @@ class ServerCommand extends Command
*/
public function __construct($appRoot, $configurationManager)
{
$this->appRoot = $appRoot;
$this->appRoot = $appRoot;
$this->configurationManager = $configurationManager;

parent::__construct();
Expand Down Expand Up @@ -71,17 +72,19 @@ protected function execute(InputInterface $input, OutputInterface $output)

$finder = new PhpExecutableFinder();
if (false === $binary = $finder->find()) {
$this->getIo()->error($this->trans('commands.server.errors.binary'));
$this->getIo()->error(
$this->trans('commands.server.errors.binary')
);

return 1;
}

$router = $this->configurationManager
->getVendorCoreDirectory() . 'router.php';
->getVendorCoreDirectory().'router.php';

$processBuilder = new ProcessBuilder([$binary, '-S', $address, $router]);
$processBuilder->setTimeout(null);
$processBuilder->setWorkingDirectory($this->appRoot);
$process = $processBuilder->getProcess();
$process = new Process([$binary, '-S', $address, $router]);
$process->setTimeout(null);
$process->setWorkingDirectory($this->appRoot);

$this->getIo()->success(
sprintf(
Expand All @@ -97,7 +100,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
)
);

if ($this->getIo()->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) {
if ($this->getIo()->getVerbosity()
> OutputInterface::VERBOSITY_NORMAL
) {
$callback = [$this, 'outputCallback'];
} else {
$callback = null;
Expand All @@ -108,14 +113,16 @@ protected function execute(InputInterface $input, OutputInterface $output)

if (!$process->isSuccessful()) {
$this->getIo()->error($process->getErrorOutput());

return 1;
}

return 0;
}

/**
* @param string $address
* @param string $address
*
* @return string
*/
private function validatePort($address)
Expand All @@ -129,7 +136,7 @@ private function validatePort($address)
}

if (fsockopen($host, $port)) {
$port = rand(8888, 9999);
$port = rand(8888, 9999);
$address = sprintf(
'%s:%s',
$host,
Expand All @@ -147,4 +154,5 @@ public function outputCallback($type, $buffer)
// TODO: seems like $type is Process::ERR always
echo $buffer;
}

}

0 comments on commit 566474a

Please sign in to comment.