コード例 #1
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());
 }
コード例 #2
0
 public function testExceptionIsThrownWithWrongParameterToAddArgument()
 {
     $this->expectException(InvalidArgumentException::class);
     $msg = 'Parameter: "argument" can only be one of: "string", "PhpSchool\\PhpWorkshop\\CommandArgument" ';
     $msg .= 'Received: "stdClass"';
     $this->expectExceptionMessage($msg);
     $definition = new CommandDefinition('animal', [], 'strlen');
     $definition->addArgument(new \stdClass());
 }
コード例 #3
0
 /**
  * Add any extra required arguments to the command.
  *
  * @param CommandDefinition $commandDefinition
  */
 public function configureInput(CommandDefinition $commandDefinition)
 {
     $commandDefinition->addArgument(CommandArgument::required('program'));
 }
コード例 #4
0
ファイル: CommandRouter.php プロジェクト: jacmoe/php-workshop
 /**
  * @param CommandDefinition $command
  * @param array $args
  * @return int
  */
 private function resolveCallable(CommandDefinition $command, array $args)
 {
     $commandCallable = $command->getCommandCallable();
     if (is_callable($commandCallable)) {
         return $this->callCommand($commandCallable, $args);
     }
     if (!is_string($commandCallable)) {
         throw new \RuntimeException('Callable must be a callable or a container entry for a callable service');
     }
     if (!$this->container->has($commandCallable)) {
         throw new \RuntimeException(sprintf('Container has no entry named: "%s"', $commandCallable));
     }
     $callable = $this->container->get($commandCallable);
     if (!is_callable($callable)) {
         throw new \RuntimeException(sprintf('Container entry: "%s" not callable', $commandCallable));
     }
     $return = $this->callCommand($callable, $args);
     if (is_int($return)) {
         return $return;
     }
     return 0;
 }
コード例 #5
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);
 }