Exemple #1
0
 /**
  * Adds a command object.
  *
  * If a command with the same name already exists, it will be overridden.
  *
  * @param AbstractCommand $command A Command object
  *
  * @return AbstractCommand The registered command
  *
  * @api
  */
 public function add(AbstractCommand $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;
 }