/** * @param Operation $operation * @param ProcessEvent $event * @return ResponseInterface */ public static function fromOperation(Operation $operation, ProcessEvent $event) { $operationConfig = $operation->toArray(); if (!isset($operationConfig['responseDataRoot'])) { throw new Exception\RuntimeException(sprintf('No response data root configured for operation "%s"', $operation->getName())); } return new static($event->getResponse(), $operationConfig['responseDataRoot']); }
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; }
/** * Create the root XML element to use with a request * * @param Operation $operation Operation object * * @return \XMLWriter */ protected function createRootElement(Operation $operation) { static $defaultRoot = array('name' => 'Request'); // If no root element was specified, then just wrap the XML in 'Request' $root = $operation->getData('xmlRoot') ?: $defaultRoot; // Allow the XML declaration to be customized with xmlEncoding $encoding = $operation->getData('xmlEncoding'); $writer = $this->startDocument($encoding); $writer->startElement($root['name']); // Create the wrapping element with no namespaces if no namespaces were present if (!empty($root['namespaces'])) { // Create the wrapping element with an array of one or more namespaces foreach ((array) $root['namespaces'] as $prefix => $uri) { $nsLabel = 'xmlns'; if (!is_numeric($prefix)) { $nsLabel .= ':' . $prefix; } $writer->writeAttribute($nsLabel, $uri); } } return $writer; }
public function testHasAdditionalParameters() { $o = new Operation(array('additionalParameters' => array('type' => 'string', 'name' => 'binks'), 'parameters' => array('foo' => array('type' => 'integer'))), new Description([])); $this->assertEquals('string', $o->getAdditionalParameters()->getType()); }
/** * Create a request for an operation with a uri merged onto a base URI */ private function createCommandWithUri(Operation $operation, CommandInterface $command, ServiceClientInterface $client) { // Get the path values and use the client config settings $variables = []; 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]; } } } } // Expand the URI template. $uri = Utils::uriTemplate($operation->getUri(), $variables); return $client->getHttpClient()->createRequest($operation->getHttpMethod(), $this->description->getBaseUrl()->combine($uri), $command['request_options'] ?: []); }
public function getName() { return $this->operation->getName(); }