Example #1
0
 public function run(Request $request = null)
 {
     if (null === $request) {
         $request = Request::createAuto();
     }
     $this->request = $request;
     try {
         $this->reader = new RequestMapper();
         $this->reader->read($request, $this->command->optionsArray());
     } catch (Exception $exception) {
         $this->response->error($exception->getMessage());
         return $this;
     }
     foreach ($this->reader->values as $name => $value) {
         $this->command->{$name} = $value;
     }
     $this->command->performAction();
     return $this;
 }
Example #2
0
 public function run(Request $request = null)
 {
     if (null === $request) {
         $request = Request::createAuto();
     }
     $this->request = $request;
     try {
         if (!$this->command instanceof Command\Application) {
             throw new Command\Exception('Application required', Command\Exception::INVALID_ARGUMENT);
         }
         $this->reader = new RequestReader();
         $this->reader->read($request, $this->command->optionsArray());
     } catch (Command\Exception $exception) {
         if (empty($this->reader->values['action'])) {
             // TODO symbolize 'action' literal
             $this->response->error($exception->getMessage());
             $this->response->addContent('Use --help to show information.');
             return $this;
         }
     }
     foreach ($this->reader->values as $name => $value) {
         $this->command->{$name} = $value;
     }
     if (isset($this->command->action)) {
         $action = $this->command->action;
         $commandDefinition = $this->command->definition()->actions[$action];
         $command = new $commandDefinition->commandClass();
         $runner = new \Yaoi\Cli\Command\Runner($command);
         $runner->commandName = $this->commandName . ' ' . $action;
         $runner->commandVersion = $this->commandVersion;
         $runner->commandDescription = $this->commandDescription . ($runner->commandDescription ? PHP_EOL . $runner->commandDescription : '');
         $runner->skipFirstTokens = 1;
         $runner->run($request);
     }
     return $this;
 }
 /**
  * Checks properties values
  *
  * @throws \Exception   if some property contains incorrect value.
  */
 protected function checkProperties()
 {
     if (!$this->getRequestReader() instanceof RequestReader) {
         $this->throwException('Class for RequestReader should be inherit from "%baseClass%" ' . '(see SmartLoad option/property "%option%")', array('%baseClass%' => RequestReader::className(), '%option%' => 'requestReaderClassName'));
     }
     $supportedHashAlgorithms = hash_algos();
     if (is_string($this->hashMethod) && !in_array($this->hashMethod, $supportedHashAlgorithms)) {
         $this->throwException('Incorrect hashing method (see SmartLoad option/property "%option%"). ' . 'Supported hash algorithms: %hashAlgorithms% ', array('%hashAlgorithms%' => join(', ', $supportedHashAlgorithms), '%option%' => 'hashMethod'));
     }
     // todo check other properties
 }