add() public method

If a command exists with the same name in the collection, that command is overwritten.
public add ( Command $command )
$command Command The command to add.
 public function testIterator()
 {
     $this->collection->add($ls = new Command(new CommandConfig('ls')));
     $this->collection->add($cd = new Command(new CommandConfig('cd')));
     $result = iterator_to_array($this->collection);
     $this->assertSame(array('ls' => $ls, 'cd' => $cd), $result);
 }
 private function addCommand(CommandConfig $config)
 {
     if (!$config->isEnabled()) {
         return;
     }
     $this->validateCommandName($config);
     $command = new Command($config, $this);
     $this->commands->add($command);
     if ($config->isDefault()) {
         $this->defaultCommands->add($command);
     }
     if (!$config->isAnonymous()) {
         $this->namedCommands->add($command);
     }
 }
Beispiel #3
0
 /**
  * Adds a sub-command.
  *
  * @param SubCommandConfig $config The sub-command configuration.
  *
  * @throws CannotAddCommandException If the command cannot be added.
  */
 private function addSubCommand(SubCommandConfig $config)
 {
     if (!$config->isEnabled()) {
         return;
     }
     $this->validateSubCommandName($config);
     $command = new self($config, $this->application, $this);
     $this->subCommands->add($command);
     if ($config->isDefault()) {
         $this->defaultSubCommands->add($command);
     }
     if (!$config->isAnonymous()) {
         $this->namedSubCommands->add($command);
     }
 }