Ejemplo n.º 1
0
 /**
  * Resolves and checks the current command method name
  *
  * Note: The resulting command method name might not have the correct case, which isn't a problem because PHP is case insensitive regarding method names.
  *
  * @return string Method name of the current command
  * @throws NoSuchCommandException
  */
 protected function resolveCommandMethodName()
 {
     $commandMethodName = $this->request->getControllerCommandName() . 'Command';
     if (!is_callable(array($this, $commandMethodName))) {
         throw new NoSuchCommandException(sprintf('A command method "%s()" does not exist in controller "%s".', $commandMethodName, get_class($this)), 1300902143);
     }
     return $commandMethodName;
 }
 /**
  * Calls the specified command method and passes the arguments.
  *
  * If the command returns a string, it is appended to the content in the
  * response object. If the command doesn't return anything and a valid
  * view exists, the view is rendered automatically.
  *
  * @return void
  */
 protected function callCommandMethod()
 {
     $preparedArguments = array();
     /** @var Argument $argument */
     foreach ($this->arguments as $argument) {
         $preparedArguments[] = $argument->getValue();
     }
     $command = new Command(get_class($this), $this->request->getControllerCommandName());
     if ($command->isDeprecated()) {
         $suggestedCommandMessage = '';
         $relatedCommandIdentifiers = $command->getRelatedCommandIdentifiers();
         if ($relatedCommandIdentifiers !== array()) {
             $suggestedCommandMessage = sprintf(', use the following command%s instead: %s', count($relatedCommandIdentifiers) > 1 ? 's' : '', implode(', ', $relatedCommandIdentifiers));
         }
         $this->outputLine('<b>Warning:</b> This command is <b>DEPRECATED</b>%s%s', array($suggestedCommandMessage, PHP_EOL));
     }
     $commandResult = call_user_func_array(array($this, $this->commandMethodName), $preparedArguments);
     if (is_string($commandResult) && strlen($commandResult) > 0) {
         $this->response->appendContent($commandResult);
     } elseif (is_object($commandResult) && method_exists($commandResult, '__toString')) {
         $this->response->appendContent((string) $commandResult);
     }
 }