/**
  * {@inheritdoc}
  */
 protected function handleParsing(AbstractCommand $command, Response $response, $contentType)
 {
     $operation = $command->getOperation();
     $type = $operation->getResponseType();
     $model = null;
     if ($type == OperationInterface::TYPE_MODEL) {
         $model = $operation->getServiceDescription()->getModel($operation->getResponseClass());
     } elseif ($type == OperationInterface::TYPE_CLASS) {
         $responseClassInterface = __NAMESPACE__ . '\\ResponseClassInterface';
         $className = $operation->getResponseClass();
         if (!class_exists($className)) {
             throw new ResponseClassException("{$className} does not exist");
         } elseif (!is_subclass_of($className, $responseClassInterface)) {
             throw new ResponseClassException("{$className} must implement {$responseClassInterface}");
         }
         return $className::fromCommand($command);
     }
     if (!$model) {
         // Return basic processing if the responseType is not model or the model cannot be found
         return parent::handleParsing($command, $response, $contentType);
     } elseif ($command->get(AbstractCommand::RESPONSE_PROCESSING) != AbstractCommand::TYPE_MODEL) {
         // Returns a model with no visiting if the command response processing is not model
         return new Model(parent::handleParsing($command, $response, $contentType), $model);
     } else {
         return new Model($this->visitResult($model, $command, $response), $model);
     }
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 protected function handleParsing(AbstractCommand $command, Response $response, $contentType)
 {
     $operation = $command->getOperation();
     $model = $operation->getResponseType() == OperationInterface::TYPE_MODEL ? $operation->getServiceDescription()->getModel($operation->getResponseClass()) : null;
     if (!$model) {
         // Return basic processing if the responseType is not model or the model cannot be found
         return parent::handleParsing($command, $response, $contentType);
     } elseif ($command->get(AbstractCommand::RESPONSE_PROCESSING) != AbstractCommand::TYPE_MODEL) {
         // Returns a model with no visiting if the command response processing is not model
         return new Model(parent::handleParsing($command, $response, $contentType), $model);
     } else {
         return new Model($this->visitResult($model, $command, $response), $model);
     }
 }
Esempio n. 3
0
 /**
  * Determines whether a command's response type is a model
  *
  * @param Guzzle\Service\Command\AbstractCommand $command
  *
  * @return boolean
  */
 public function responseTypeIsModel(AbstractCommand $command)
 {
     $operation = $command->getOperation();
     $processing = $command->get(AbstractCommand::RESPONSE_PROCESSING);
     $description = $operation->getServiceDescription();
     return $operation->getResponseType() == OperationInterface::TYPE_MODEL && $description->hasModel($operation->getResponseClass()) && $processing == AbstractCommand::TYPE_MODEL;
 }