/** * @param Input $input * * @return int * * @throws UnknownCommandException If the command is not found * @throws Exception\UndefinedArgumentException If the argument is undefined * * @api */ public function run(Input $input) { $commandName = $input->getCommandName(); if (!isset($this->commands[$commandName])) { throw new UnknownCommandException($input, $this->commands); } $command = $this->commands[$commandName]; return $command->execute($input); }
/** * @param Input $input * @param array $commands * * @api */ public function __construct(Input $input, array $commands) { $this->input = $input; $this->commands = $commands; parent::__construct(sprintf('Unknown command: "%s"', $input->getCommandName())); }