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

Breadcrumb

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

function ExecCommand::execute

Overrides Command::execute

File

vendor/composer/composer/src/Composer/Command/ExecCommand.php, line 78

Class

ExecCommand
@author Davey Shafik <me@daveyshafik.com>

Namespace

Composer\Command

Code

protected function execute(InputInterface $input, OutputInterface $output) : int {
    $composer = $this->requireComposer();
    if ($input->getOption('list') || null === $input->getArgument('binary')) {
        $bins = $this->getBinaries(true);
        if ([] === $bins) {
            $binDir = $composer->getConfig()
                ->get('bin-dir');
            throw new \RuntimeException("No binaries found in composer.json or in bin-dir ({$binDir})");
        }
        $this->getIO()
            ->write(<<<EOT
<comment>Available binaries:</comment>
EOT
);
        foreach ($bins as $bin) {
            $this->getIO()
                ->write(<<<EOT
<info>- {<span class="php-variable">$bin</span>}</info>
EOT
);
        }
        return 0;
    }
    $binary = $input->getArgument('binary');
    $dispatcher = $composer->getEventDispatcher();
    $dispatcher->addListener('__exec_command', $binary);
    // If the CWD was modified, we restore it to what it was initially, as it was
    // most likely modified by the global command, and we want exec to run in the local working directory
    // not the global one
    if (getcwd() !== $this->getApplication()
        ->getInitialWorkingDirectory() && $this->getApplication()
        ->getInitialWorkingDirectory() !== false) {
        try {
            chdir($this->getApplication()
                ->getInitialWorkingDirectory());
        } catch (\Exception $e) {
            throw new \RuntimeException('Could not switch back to working directory "' . $this->getApplication()
                ->getInitialWorkingDirectory() . '"', 0, $e);
        }
    }
    return $dispatcher->dispatchScript('__exec_command', true, $input->getArgument('args'));
}

API Navigation

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