Webmozart\Console\Api\Command\CommandCollection::add PHP Method

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 add(Command $command)
    {
        $name = $command->getName();
        $this->commands[$name] = $command;
        if ($shortName = $command->getShortName()) {
            $this->shortNameIndex[$shortName] = $name;
        }
        foreach ($command->getAliases() as $alias) {
            $this->aliasIndex[$alias] = $name;
        }
        ksort($this->aliasIndex);
    }

Usage Example

Ejemplo n.º 1
0
 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);
 }
All Usage Examples Of Webmozart\Console\Api\Command\CommandCollection::add