function GlobalCommand::prepareSubcommandInput
2 calls to GlobalCommand::prepareSubcommandInput()
- GlobalCommand::complete in vendor/
composer/ composer/ src/ Composer/ Command/ GlobalCommand.php - @inheritdoc
- GlobalCommand::run in vendor/
composer/ composer/ src/ Composer/ Command/ GlobalCommand.php
File
-
vendor/
composer/ composer/ src/ Composer/ Command/ GlobalCommand.php, line 122
Class
- GlobalCommand
- @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
Composer\CommandCode
private function prepareSubcommandInput(InputInterface $input, bool $quiet = false) : StringInput {
// TODO remove for Symfony 6+ as it is then in the interface
if (!method_exists($input, '__toString')) {
// @phpstan-ignore-line
throw new \LogicException('Expected an Input instance that is stringable, got ' . get_class($input));
}
// The COMPOSER env var should not apply to the global execution scope
if (Platform::getEnv('COMPOSER')) {
Platform::clearEnv('COMPOSER');
}
// change to global dir
$config = Factory::createConfig();
$home = $config->get('home');
if (!is_dir($home)) {
$fs = new Filesystem();
$fs->ensureDirectoryExists($home);
if (!is_dir($home)) {
throw new \RuntimeException('Could not create home directory');
}
}
try {
chdir($home);
} catch (\Exception $e) {
throw new \RuntimeException('Could not switch to home directory "' . $home . '"', 0, $e);
}
if (!$quiet) {
$this->getIO()
->writeError('<info>Changed current directory to ' . $home . '</info>');
}
// create new input without "global" command prefix
$input = new StringInput(Preg::replace('{\\bg(?:l(?:o(?:b(?:a(?:l)?)?)?)?)?\\b}', '', $input->__toString(), 1));
$this->getApplication()
->resetComposer();
return $input;
}