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

Breadcrumb

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

function Application::doRun

Same name in this branch
  1. 11.1.x vendor/composer/composer/src/Composer/Console/Application.php \Composer\Console\Application::doRun()

Runs the current application.

Return value

int 0 if everything went fine, or an error code

3 calls to Application::doRun()
Application::doRun in vendor/composer/composer/src/Composer/Console/Application.php
Runs the current application.
Application::doRun in vendor/composer/composer/src/Composer/Console/Application.php
Runs the current application.
Application::run in vendor/symfony/console/Application.php
Runs the current application.
1 method overrides Application::doRun()
Application::doRun in vendor/composer/composer/src/Composer/Console/Application.php
Runs the current application.

File

vendor/symfony/console/Application.php, line 245

Class

Application
An Application is the container for a collection of commands.

Namespace

Symfony\Component\Console

Code

public function doRun(InputInterface $input, OutputInterface $output) : int {
    if (true === $input->hasParameterOption([
        '--version',
        '-V',
    ], true)) {
        $output->writeln($this->getLongVersion());
        return 0;
    }
    try {
        // Makes ArgvInput::getFirstArgument() able to distinguish an option from an argument.
        $input->bind($this->getDefinition());
    } catch (ExceptionInterface) {
        // Errors must be ignored, full binding/validation happens later when the command is known.
    }
    $name = $this->getCommandName($input);
    if (true === $input->hasParameterOption([
        '--help',
        '-h',
    ], true)) {
        if (!$name) {
            $name = 'help';
            $input = new ArrayInput([
                'command_name' => $this->defaultCommand,
            ]);
        }
        else {
            $this->wantHelps = true;
        }
    }
    if (!$name) {
        $name = $this->defaultCommand;
        $definition = $this->getDefinition();
        $definition->setArguments(array_merge($definition->getArguments(), [
            'command' => new InputArgument('command', InputArgument::OPTIONAL, $definition->getArgument('command')
                ->getDescription(), $name),
        ]));
    }
    try {
        $this->runningCommand = null;
        // the command name MUST be the first element of the input
        $command = $this->find($name);
    } catch (\Throwable $e) {
        if ($e instanceof CommandNotFoundException && !$e instanceof NamespaceNotFoundException && 1 === \count($alternatives = $e->getAlternatives()) && $input->isInteractive()) {
            $alternative = $alternatives[0];
            $style = new SymfonyStyle($input, $output);
            $output->writeln('');
            $formattedBlock = (new FormatterHelper())->formatBlock(\sprintf('Command "%s" is not defined.', $name), 'error', true);
            $output->writeln($formattedBlock);
            if (!$style->confirm(\sprintf('Do you want to run "%s" instead? ', $alternative), false)) {
                if (null !== $this->dispatcher) {
                    $event = new ConsoleErrorEvent($input, $output, $e);
                    $this->dispatcher
                        ->dispatch($event, ConsoleEvents::ERROR);
                    return $event->getExitCode();
                }
                return 1;
            }
            $command = $this->find($alternative);
        }
        else {
            if (null !== $this->dispatcher) {
                $event = new ConsoleErrorEvent($input, $output, $e);
                $this->dispatcher
                    ->dispatch($event, ConsoleEvents::ERROR);
                if (0 === $event->getExitCode()) {
                    return 0;
                }
                $e = $event->getError();
            }
            try {
                if ($e instanceof CommandNotFoundException && ($namespace = $this->findNamespace($name))) {
                    $helper = new DescriptorHelper();
                    $helper->describe($output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output, $this, [
                        'format' => 'txt',
                        'raw_text' => false,
                        'namespace' => $namespace,
                        'short' => false,
                    ]);
                    return isset($event) ? $event->getExitCode() : 1;
                }
                throw $e;
            } catch (NamespaceNotFoundException) {
                throw $e;
            }
        }
    }
    if ($command instanceof LazyCommand) {
        $command = $command->getCommand();
    }
    $this->runningCommand = $command;
    $exitCode = $this->doRunCommand($command, $input, $output);
    $this->runningCommand = null;
    return $exitCode;
}

API Navigation

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