Ejemplo n.º 1
0
 /**
  * @param CommandDefinition $c
  */
 private function addCommand(CommandDefinition $c)
 {
     if (isset($this->commands[$c->getName()])) {
         throw new \InvalidArgumentException(sprintf('Command with name: "%s" already exists', $c->getName()));
     }
     $this->commands[$c->getName()] = $c;
 }
Ejemplo n.º 2
0
 public function testGettersSetters()
 {
     $callable = function () {
     };
     $definition = new CommandDefinition('animal', ['name'], $callable);
     $this->assertSame($definition->getName(), 'animal');
     $this->assertSame(['name'], $definition->getRequiredArgs());
     $this->assertSame($callable, $definition->getCommandCallable());
 }
 public function testGettersSettersWithObjArgs()
 {
     $callable = function () {
     };
     $definition = new CommandDefinition('animal', [new CommandArgument('name')], $callable);
     $this->assertSame($definition->getName(), 'animal');
     $requiredArgs = $definition->getRequiredArgs();
     $this->assertCount(1, $requiredArgs);
     $this->assertInstanceOf(CommandArgument::class, $requiredArgs[0]);
     $this->assertSame('name', $requiredArgs[0]->getName());
     $this->assertSame($callable, $definition->getCommandCallable());
 }
Ejemplo n.º 4
0
 /**
  * @param CommandDefinition $command
  * @param callable $callable
  * @param Input $input
  * @return int
  */
 private function callCommand(CommandDefinition $command, callable $callable, Input $input)
 {
     $this->eventDispatcher->dispatch(new Event\Event('route.pre.invoke'));
     $this->eventDispatcher->dispatch(new Event\Event(sprintf('route.pre.invoke.%s', $command->getName())));
     return $callable($input);
 }