public function after(GuzzleCommandInterface $command, RequestInterface $request, Operation $operation, array $context) { foreach ($this->buffered as $param) { $this->visitWithValue($command[$param->getName()], $param, $command); } $this->buffered = array(); $additional = $operation->getAdditionalParameters(); if ($additional && $additional->getLocation() == $this->locationName) { foreach ($command->toArray() as $key => $value) { if (!$operation->hasParam($key)) { $additional->setName($key); $this->visitWithValue($value, $additional, $command); } } $additional->setName(null); } // If data was found that needs to be serialized, then do so $xml = null; if ($this->writer) { $xml = $this->finishDocument($this->writer); } elseif ($operation->getData('xmlAllowEmpty')) { // Check if XML should always be sent for the command $writer = $this->createRootElement($operation); $xml = $this->finishDocument($writer); } if ($xml) { $request->setBody(Stream::factory($xml)); // Don't overwrite the Content-Type if one is set if ($this->contentType && !$request->hasHeader('Content-Type')) { $request->setHeader('Content-Type', $this->contentType); } } $this->writer = null; }
public function after(CommandInterface $command, RequestInterface $request, Operation $operation, array $context) { $additional = $operation->getAdditionalParameters(); if ($additional && $additional->getLocation() == $this->locationName) { foreach ($command->toArray() as $key => $value) { if (!$operation->hasParam($key)) { $request->setHeader($key, $additional->filter($value)); } } } }
public function after(GuzzleCommandInterface $command, RequestInterface $request, Operation $operation, array $context) { $additional = $operation->getAdditionalParameters(); if ($additional && $additional->getLocation() == $this->locationName) { foreach ($command->toArray() as $key => $value) { if (!$operation->hasParam($key)) { $request->getQuery()[$key] = $this->prepareValue($value, $additional); } } } }
public function after(CommandInterface $command, RequestInterface $request, Operation $operation, array $context) { $additional = $operation->getAdditionalParameters(); if ($additional && $additional->getLocation() == $this->locationName) { $body = $request->getBody(); if (!$body instanceof PostBodyInterface) { throw new \RuntimeException('Must be a POST body interface'); } foreach ($command->toArray() as $key => $value) { if (!$operation->hasParam($key)) { $body->setField($key, $this->prepareValue($value, $additional)); } } } }
public function after(GuzzleCommandInterface $command, RequestInterface $request, Operation $operation, array $context) { $data = $this->jsonData; $this->jsonData = null; // Add additional parameters to the JSON document $additional = $operation->getAdditionalParameters(); if ($additional && $additional->getLocation() == $this->locationName) { foreach ($command->toArray() as $key => $value) { if (!$operation->hasParam($key)) { $data[$key] = $this->prepareValue($value, $additional); } } } // Don't overwrite the Content-Type if one is set if ($this->jsonContentType && !$request->hasHeader('Content-Type')) { $request->setHeader('Content-Type', $this->jsonContentType); } $request->setBody(Stream::factory(json_encode($data))); }
/** * @param Operation $operation * @param array $params * * @return array */ private function getParametersForSignature($operation, $params) { // gather all parameters needed to sign the request $signatureParams = array(); // add all parameters defined in the service description which have location=query foreach ($operation->getParams() as $param) { /** @var Parameter $param */ if ($param->getLocation() == 'query' && (isset($params[$param->getName()]) || $param->getDefault())) { $signatureParams[$param->getName()] = isset($params[$param->getName()]) ? $params[$param->getName()] : $param->getDefault(); } } // check if the command allows additional parameters with location=query if ($operation->getAdditionalParameters()->getLocation() == 'query') { // if yes, add all additionally given parameters from $params skipping predefined parameters foreach ($params as $name => $value) { if (!$operation->hasParam($name)) { $signatureParams[$name] = $value; } } } return $signatureParams; }