public function after(CommandInterface $command, RequestInterface $request) { $xml = null; // If data was found that needs to be serialized, then do so if (isset($this->data[$command])) { $xml = $this->finishDocument($this->data[$command]); unset($this->data[$command]); } else { // Check if XML should always be sent for the command $operation = $command->getOperation(); if ($operation->getData('xmlAllowEmpty')) { $xmlWriter = $this->createRootElement($operation); $xml = $this->finishDocument($xmlWriter); } } if ($xml) { // Don't overwrite the Content-Type if one is set if ($this->contentType && !$request->hasHeader('Content-Type')) { $request->setHeader('Content-Type', $this->contentType); } $request->setBody($xml); } }
/** * Create a request for the command and operation * * @param CommandInterface $command Command to create a request for * * @return RequestInterface */ protected function createRequest(CommandInterface $command) { $operation = $command->getOperation(); $client = $command->getClient(); $options = $command[AbstractCommand::REQUEST_OPTIONS] ?: array(); // If the command does not specify a template, then assume the base URL of the client if (!($uri = $operation->getUri())) { return $client->createRequest($operation->getHttpMethod(), $client->getBaseUrl(), null, null, $options); } // Get the path values and use the client config settings $variables = array(); foreach ($operation->getParams() as $name => $arg) { if ($arg->getLocation() == 'uri') { if (isset($command[$name])) { $variables[$name] = $arg->filter($command[$name]); if (!is_array($variables[$name])) { $variables[$name] = (string) $variables[$name]; } } } } return $client->createRequest($operation->getHttpMethod(), array($uri, $variables), null, null, $options); }
/** * Parse a class object * * @param CommandInterface $command Command to parse into an object * * @return mixed * @throws ResponseClassException */ protected function parseClass(CommandInterface $command) { // Emit the operation.parse_class event. If a listener injects a 'result' property, then that will be the result $event = new CreateResponseClassEvent(array('command' => $command)); $command->getClient()->getEventDispatcher()->dispatch('command.parse_response', $event); if ($result = $event->getResult()) { return $result; } $className = $command->getOperation()->getResponseClass(); if (!method_exists($className, 'fromCommand')) { throw new ResponseClassException("{$className} must exist and implement a static fromCommand() method"); } return $className::fromCommand($command); }