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

Breadcrumb

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

function Application::add

Adds a command object.

If a command with the same name already exists, it will be overridden. If the command is not enabled it will not be added.

5 calls to Application::add()
Application::addCommands in vendor/symfony/console/Application.php
Adds an array of command objects.
Application::doRun in vendor/composer/composer/src/Composer/Console/Application.php
Runs the current application.
Application::has in vendor/symfony/console/Application.php
Returns true if the command exists, false otherwise.
Application::init in vendor/symfony/console/Application.php
Application::register in vendor/symfony/console/Application.php
Registers a new command.

File

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

Class

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

Namespace

Symfony\Component\Console

Code

public function add(Command $command) : ?Command {
    $this->init();
    $command->setApplication($this);
    if (!$command->isEnabled()) {
        $command->setApplication(null);
        return null;
    }
    if (!$command instanceof LazyCommand) {
        // Will throw if the command is not correctly initialized.
        $command->getDefinition();
    }
    if (!$command->getName()) {
        throw new LogicException(\sprintf('The command defined in "%s" cannot have an empty name.', get_debug_type($command)));
    }
    $this->commands[$command->getName()] = $command;
    foreach ($command->getAliases() as $alias) {
        $this->commands[$alias] = $command;
    }
    return $command;
}

API Navigation

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