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->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)) { $query = $request->getQuery(); $query[$key] = $this->prepareValue($value, $additional); } } } }
public function after(GuzzleCommandInterface $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))); }
/** * Create a request for an operation with a uri merged onto a base URI */ private function createCommandWithUri(GuzzleCommandInterface $command, GuzzleClientInterface $client) { // Get the path values and use the client config settings $variables = array(); $operation = $command->getOperation(); foreach ($operation->getParams() as $name => $arg) { /* @var Parameter $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->getHttpClient()->createRequest($operation->getHttpMethod(), array($client->getDescription()->getBaseUrl()->combine($operation->getUri()), $variables), $command['request_options'] ?: array()); }
private function visitWithValue($value, Parameter $param, GuzzleCommandInterface $command) { if (!$this->writer) { $this->createRootElement($command->getOperation()); } $this->addXml($this->writer, $param, $value); }