You are here

public function Application::add in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/console/Application.php \Symfony\Component\Console\Application::add()

Adds a command object.

If a command with the same name already exists, it will be overridden.

Parameters

Command $command A Command object:

Return value

Command The registered command

5 calls to Application::add()
Application::addCommands in vendor/symfony/console/Application.php
Adds an array of command objects.
Application::register in vendor/symfony/console/Application.php
Registers a new command.
Application::__construct in vendor/symfony/console/Application.php
Constructor.
CustomDefaultCommandApplication::__construct in vendor/symfony/console/Tests/ApplicationTest.php
Overwrites the constructor in order to set a different default command.
DescriptorApplication2::__construct in vendor/symfony/console/Tests/Fixtures/DescriptorApplication2.php
Constructor.

File

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

Class

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

Namespace

Symfony\Component\Console

Code

public function add(Command $command) {
  $command
    ->setApplication($this);
  if (!$command
    ->isEnabled()) {
    $command
      ->setApplication(null);
    return;
  }
  if (null === $command
    ->getDefinition()) {
    throw new \LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', get_class($command)));
  }
  $this->commands[$command
    ->getName()] = $command;
  foreach ($command
    ->getAliases() as $alias) {
    $this->commands[$alias] = $command;
  }
  return $command;
}