/** * {@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); } }
/** * {@inheritdoc} */ protected function build() { // Prepare and serialize the request $this->request = $this->getRequestSerializer()->prepare($this); // If no response parser is set, add the default parser if a model matching the responseClass is found if (!$this->responseParser) { $this->responseParser = $this->operation->getResponseType() == OperationInterface::TYPE_MODEL && $this->get(self::RESPONSE_PROCESSING) == self::TYPE_MODEL ? OperationResponseParser::getInstance() : DefaultResponseParser::getInstance(); } }
/** * {@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); } }
/** * {@inheritdoc} */ protected function build() { // By default, JSON commands with AWS require no response model processing if ($this->operation->getResponseType() == OperationInterface::TYPE_MODEL && $this->get(self::RESPONSE_PROCESSING) == self::TYPE_MODEL) { $this->responseParser = $this->get('command.model_processing') ? OperationResponseParser::getInstance() : NoTranslationOperationResponseParser::getInstance(); } else { $this->responseParser = DefaultResponseParser::getInstance(); } parent::build(); // Ensure that the body of the request ALWAYS includes some JSON. By default, this is an empty object. if (!$this->request->getBody()) { $this->request->setBody('{}'); } // Never send the Expect header when interacting with a JSON query service $this->request->removeHeader('Expect'); }
protected function handleParsing(CommandInterface $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) { return $this->parseClass($command); } if (!$model) { return parent::handleParsing($command, $response, $contentType); } elseif ($command[AbstractCommand::RESPONSE_PROCESSING] != AbstractCommand::TYPE_MODEL) { return new Model(parent::handleParsing($command, $response, $contentType)); } else { return new Model($this->visitResult($model, $command, $response), $this->schemaInModels ? $model : null); } }
/** * {@inheritdoc} */ public function parseForContentType(AbstractCommand $command, Response $response, $contentType) { // Perform that default native processing $result = parent::parseForContentType($command, $response, $contentType); $operation = $command->getOperation(); $model = $operation->getResponseType() == 'model' && $command->get(AbstractCommand::RESPONSE_PROCESSING) == AbstractCommand::TYPE_MODEL ? $operation->getServiceDescription()->getModel($operation->getResponseClass()) : null; // No further processing is needed if the responseType is not model or using native responses, or the model // cannot be found if (!$model) { return $result; } if ($result instanceof \SimpleXMLElement) { $result = json_decode(json_encode($result), true); } elseif ($result instanceof Response) { $result = array(); } // Perform transformations on the result using location visitors $this->visitResult($model, $command, $response, $result); return new Model($result, $model); }
protected function handleParsing(CommandInterface $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) { return $this->parseClass($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[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)); } else { // Only inject the schema into the model if "schemaInModel" is true return new Model($this->visitResult($model, $command, $response), $this->schemaInModels ? $model : null); } }
/** * Create the result of the command after the request has been completed. * Override this method in subclasses to customize this behavior */ protected function process() { $this->result = $this[self::RESPONSE_PROCESSING] != self::TYPE_RAW ? DefaultResponseParser::getInstance()->parse($this) : $this->request->getResponse(); }