ProcessFactory.php in Automatic Updates 8.2
File
package_manager/src/ProcessFactory.php
View source
<?php
namespace Drupal\package_manager;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\File\FileSystemInterface;
use PhpTuf\ComposerStager\Infrastructure\Process\ProcessFactory as StagerProcessFactory;
use PhpTuf\ComposerStager\Infrastructure\Process\ProcessFactoryInterface;
use Symfony\Component\Process\Process;
final class ProcessFactory implements ProcessFactoryInterface {
private $decorated;
private $fileSystem;
private $configFactory;
public function __construct(FileSystemInterface $file_system, ConfigFactoryInterface $config_factory) {
$this->decorated = new StagerProcessFactory();
$this->fileSystem = $file_system;
$this->configFactory = $config_factory;
}
private function getEnv(string $variable) {
if (function_exists('apache_getenv')) {
return apache_getenv($variable);
}
return getenv($variable);
}
public function create(array $command) : Process {
$process = $this->decorated
->create($command);
$env = $process
->getEnv();
if ($this
->isComposerCommand($command)) {
$env['COMPOSER_HOME'] = $this
->getComposerHomePath();
}
$env['PATH'] = $this
->getEnv('PATH') . ':' . dirname(PHP_BINARY);
return $process
->setEnv($env);
}
private function getComposerHomePath() : string {
$home_path = $this->fileSystem
->getTempDirectory();
$home_path .= '/automatic_updates_composer_home-';
$home_path .= $this->configFactory
->get('system.site')
->get('uuid');
$this->fileSystem
->prepareDirectory($home_path, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
return $home_path;
}
private function isComposerCommand(array $command) : bool {
$executable = $command[0];
$executable_parts = explode('/', $executable);
$file = array_pop($executable_parts);
return strpos($file, 'composer') === 0;
}
}
Classes
Name |
Description |
ProcessFactory |
Defines a process factory which sets the COMPOSER_HOME environment variable. |