Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. GlobalCommand.php

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\Command

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal