Skip to content
Snippets Groups Projects
Commit 70ef2270 authored by Adam G-H's avatar Adam G-H Committed by Ted Bowman
Browse files

Issue #3228521 by phenaproxima: Clean up ProcessFactory

parent 7886fa92
No related branches found
No related tags found
1 merge request!9Issue #3228521: Clean up ProcessFactory
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
namespace Drupal\automatic_updates\ComposerStager; namespace Drupal\automatic_updates\ComposerStager;
use PhpTuf\ComposerStager\Exception\LogicException; use PhpTuf\ComposerStager\Infrastructure\Process\ProcessFactory as StagerProcessFactory;
use PhpTuf\ComposerStager\Infrastructure\Process\ProcessFactoryInterface; use PhpTuf\ComposerStager\Infrastructure\Process\ProcessFactoryInterface;
use Symfony\Component\Process\Exception\ExceptionInterface;
use Symfony\Component\Process\Process; use Symfony\Component\Process\Process;
/** /**
...@@ -14,27 +13,49 @@ use Symfony\Component\Process\Process; ...@@ -14,27 +13,49 @@ use Symfony\Component\Process\Process;
*/ */
final class ProcessFactory implements ProcessFactoryInterface { final class ProcessFactory implements ProcessFactoryInterface {
/**
* The decorated process factory.
*
* @var \PhpTuf\ComposerStager\Infrastructure\Process\ProcessFactoryInterface
*/
private $decorated;
/**
* Constructs a ProcessFactory object.
*/
public function __construct() {
$this->decorated = new StagerProcessFactory();
}
/**
* Returns the value of an environment variable.
*
* @param string $variable
* The name of the variable.
*
* @return mixed
* The value of the variable.
*/
private function getEnv(string $variable) {
if (function_exists('apache_getenv')) {
return apache_getenv($variable);
}
return getenv($variable);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function create(array $command): Process { public function create(array $command): Process {
try { $process = $this->decorated->create($command);
if ($this->isComposerCommand($command)) {
$process = new Process($command, NULL, ['COMPOSER_HOME' => $this->getComposerHomePath()]); $env = $process->getEnv();
$path = function_exists('apache_getenv') ? apache_getenv('PATH') : getenv('PATH'); if ($this->isComposerCommand($command)) {
$path .= ':' . dirname(PHP_BINARY); $env['COMPOSER_HOME'] = $this->getComposerHomePath();
$env = $process->getEnv();
$env['PATH'] = $path;
$process->setEnv($env);
return $process;
}
return new Process($command);
// @codeCoverageIgnore
}
catch (ExceptionInterface $e) {
// @codeCoverageIgnore
throw new LogicException($e->getMessage(), (int) $e->getCode(), $e);
} }
// Ensure that the running PHP binary is in the PATH.
$env['PATH'] = $this->getEnv('PATH') . ':' . dirname(PHP_BINARY);
return $process->setEnv($env);
} }
/** /**
......
...@@ -262,39 +262,6 @@ class Updater { ...@@ -262,39 +262,6 @@ class Updater {
$this->stager->stage($command, $this->getStageDirectory()); $this->stager->stage($command, $this->getStageDirectory());
} }
/**
* Returns the value of an environment variable.
*
* @param string $variable
* The name of the variable.
*
* @return mixed
* The value of the variable.
*/
private function getEnv(string $variable) {
if (function_exists('apache_getenv')) {
return apache_getenv($variable);
}
return getenv($variable);
}
/**
* Sets the value of an environment variable.
*
* @param string $variable
* The name of the variable.
* @param mixed $value
* The value to set.
*/
private function setEnv(string $variable, $value): void {
if (function_exists('apache_setenv')) {
apache_setenv($variable, $value);
}
else {
putenv("$variable=$value");
}
}
/** /**
* Initializes an active update and returns its ID. * Initializes an active update and returns its ID.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment