/** * Expand config array with URI endpoint * * @param array $config * @param array $args * * @return array */ private function expand(array $config, array $args) { $scheme = isset($args['scheme']) ? $args['scheme'] : 'https'; $config['endpoint'] = $scheme . '://' . Utils::uriTemplate($config['endpoint'], $args); return $config; }
public function testExpandsTemplate() { $this->assertEquals('foo/123', Utils::uriTemplate('foo/{bar}', ['bar' => '123'])); }
private function configureBaseUrl(&$config) { if (!isset($config['base_url'])) { $this->baseUrl = new Url('', ''); } elseif (!is_array($config['base_url'])) { $this->baseUrl = Url::fromString($config['base_url']); } elseif (count($config['base_url']) < 2) { throw new \InvalidArgumentException('You must provide a hash of ' . 'varname options in the second element of a base_url array.'); } else { $this->baseUrl = Url::fromString(Utils::uriTemplate($config['base_url'][0], $config['base_url'][1])); $config['base_url'] = (string) $this->baseUrl; } }
/** * This method will take all of the user-provided values and populate them into a * {@see \GuzzleHttp\Message\RequestInterface} object according to each parameter schema. * Headers and URL query parameters will be set, along with the JSON body. * * In other words, it allows for the easy creation of a fully populated HTTP request in * accordance with the expectations of the remote API. * * @return \GuzzleHttp\Message\RequestInterface * @throws \Exception */ public function createRequest() { $this->validate($this->userValues); $options = ['exceptions' => false]; if (!empty($json = $this->serializeJson())) { $options['json'] = $json; } if (!empty($body = $this->serializeBody())) { $options['body'] = $body; } if (!empty($headers = $this->serializeHeaders())) { $options['headers'] = $headers; } $url = $this->serializeQuery(Utils::uriTemplate($this->path, $this->userValues)); return $this->client->createRequest($this->method, $url, $options); }
private function configureBaseUrl(&$config) { if (!isset($config['base_url'])) { $this->baseUrl = new Url('', ''); } elseif (is_array($config['base_url'])) { $this->baseUrl = Url::fromString(Utils::uriTemplate($config['base_url'][0], $config['base_url'][1])); $config['base_url'] = (string) $this->baseUrl; } else { $this->baseUrl = Url::fromString($config['base_url']); } }
/** * 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'] ?: []); }