本文整理汇总了PHP中GuzzleHttp\Psr7\Uri::withQueryValue方法的典型用法代码示例。如果您正苦于以下问题:PHP Uri::withQueryValue方法的具体用法?PHP Uri::withQueryValue怎么用?PHP Uri::withQueryValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Psr7\Uri
的用法示例。
在下文中一共展示了Uri::withQueryValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
/**
* @param RequestInterface $request
* @return RequestInterface
*/
public function __invoke(RequestInterface $request)
{
foreach ($this->params as $param => $value) {
$request = $request->withUri(Uri::withQueryValue($request->getUri(), $param, $value));
}
return $request;
}
示例2: appendQueryParams
/**
* @param RequestInterface $request
*
* @return RequestInterface
*/
private function appendQueryParams(RequestInterface $request)
{
$queryParams = $this->auth->getQueryParameters();
foreach ($queryParams as $key => $value) {
$uri = Uri::withQueryValue($request->getUri(), $key, $value);
$request = $request->withUri($uri);
}
return $request;
}
示例3: get
public static function get(array $options, $key)
{
$stack = HandlerStack::create();
$stack->unshift(Middleware::mapRequest(function (RequestInterface $request) use($key) {
return $request->withUri(Uri::withQueryValue($request->getUri(), 'key', $key));
}));
$options['handler'] = $stack;
return new Client($options);
}
示例4: research
/**
* @param RequestInterface $request
*
* @return ResponseInterface
*
* @throws ApiException | SearchLimitException
*/
public function research(RequestInterface $request)
{
try {
$response = $this->httpClient->request('GET', Uri::withQueryValue($request->getUri(), 'apikey', $this->apiKey));
return new Response($response);
} catch (\GuzzleHttp\Exception\ClientException $ex) {
throw ExceptionFactory::createThrowable($ex);
}
}
示例5: __invoke
/**
* {@inheritDoc}
*/
public function __invoke(RequestInterface $request, array $options)
{
$next = $this->nextHandler;
if (!$this->config->has('access_token') || $this->config->get('access_token') === null) {
return $next($request, $options);
}
$uri = Uri::withQueryValue($request->getUri(), 'access_token', $this->config->get('access_token')->getToken());
return parent::__invoke($request->withUri($uri)->withHeader('Content-Type', 'application/json'), $options);
}
示例6: makeUri
/**
* @param $url
* @param array $params
*
* @return \Psr\Http\Message\UriInterface
*/
private function makeUri($url, $params = array())
{
$uri = \GuzzleHttp\uri_template($this->endpoint, array_merge($this->defaults, $params));
$uri = new Psr7\Uri($uri);
// All arguments must be urlencoded (as per RFC 1738).
$query = Psr7\build_query($params, PHP_QUERY_RFC1738);
$uri = $uri->withQuery($query);
return Psr7\Uri::withQueryValue($uri, 'url', $url);
}
示例7: __invoke
/**
* Inject credentials information into the query parameters
*
* @param RequestInterface $request
* @param array $options
*
* @return GuzzleResponseInterface
*/
public function __invoke(RequestInterface $request, array $options)
{
if ($request->getUri()->getScheme() == 'https' && $options['auth'] == static::AUTH_NAME) {
$uri = Uri::withQueryValue($request->getUri(), 'client_id', $this->userKey ?: $this->apiKey);
$uri = Uri::withQueryValue($uri, 'client_secret', $this->secret);
$request = $request->withUri($uri);
}
$fn = $this->nextHandler;
return $fn($request, $options);
}
示例8: __invoke
/**
* {@inheritDoc}
*/
public function __invoke(RequestInterface $request, array $options)
{
$next = $this->nextHandler;
if (!$this->config->get('secure_requests')) {
return $next($request, $options);
}
$uri = $request->getUri();
$sig = $this->generateSig($this->getPath($uri), $this->getQueryParams($uri), $this->config->get('client_secret'));
$uri = Uri::withQueryValue($uri, 'sig', $sig);
return parent::__invoke($request->withUri($uri), $options);
}
示例9: invoke_QueryParameters_Success
/**
* @test
*/
public function invoke_QueryParameters_Success()
{
$this->auth->expects($this->once())->method('getHeaders')->willReturn([]);
$this->auth->expects($this->once())->method('getQueryParameters')->willReturn(['jwt' => 'YYYY', 'otherParam' => 'YYYY']);
$this->request->expects($this->exactly(3))->method('getUri')->willReturn($this->uri);
$this->request->expects($this->exactly(2))->method('withUri')->withConsecutive(Uri::withQueryValue($this->uri, 'jwt', 'YYYY'), Uri::withQueryValue($this->uri, 'otherParam', 'YYYY'))->willReturnSelf();
$middleware = new ConnectMiddleware($this->auth, $this->appContext);
$callable = $middleware(function (RequestInterface $actualRequest, array $options) {
$this->assertEquals($this->request, $actualRequest);
$this->assertEquals(['Hello World'], $options);
});
$callable($this->request, ['Hello World']);
}
示例10: connect
/**
* @return Client
*/
protected function connect()
{
$base_uri = $this->config->get('base_uri');
if ($this->config->has('transport') && $this->config->has('host') && $this->config->has('port')) {
$base_uri = sprintf('%s://%s:%s', $this->config->get('transport'), $this->config->get('host'), $this->config->get('port'));
}
$client_options = ['base_uri' => $base_uri];
if ($this->config->get('debug', false)) {
$client_options['debug'] = true;
}
if ($this->config->has('auth')) {
$auth = (array) $this->config->get('auth');
if (!isset($auth['username'])) {
throw new RuntimeError('Missing required "username" setting within given auth config.');
}
if (!isset($auth['password'])) {
throw new RuntimeError('Missing required "password" setting within given auth config.');
}
$client_options['auth'] = [$auth['username'], $auth['password'], isset($auth['type']) ? $auth['type'] : 'basic'];
}
if ($this->config->has('default_headers')) {
$client_options['headers'] = (array) $this->config->get('default_headers');
}
if ($this->config->has('default_options')) {
$client_options = array_merge($client_options, (array) $this->config->get('default_options')->toArray());
}
if ($this->config->has('default_query')) {
$handler = HandlerStack::create();
$handler->push(Middleware::mapRequest(function (RequestInterface $request) {
$uri = $request->getUri();
foreach ((array) $this->config->get('default_query')->toArray() as $param => $value) {
$uri = Uri::withQueryValue($uri, $param, $value);
}
return $request->withUri($uri);
}));
$client_options['handler'] = $handler;
}
return new Client($client_options);
}
示例11: attachAccessToken
/**
* Set request access_token query.
*/
protected function attachAccessToken()
{
if (!$this->accessToken) {
return;
}
// log
$this->getHttp()->addMiddleware(function (callable $handler) {
return function (RequestInterface $request, array $options) use($handler) {
$field = $this->accessToken->getQueryName();
$token = $this->accessToken->getToken();
$request = $request->withUri(Uri::withQueryValue($request->getUri(), $field, $token));
Log::debug("Request Token: {$token}");
Log::debug('Request Uri: ' . $request->getUri());
return $handler($request, $options);
};
});
// retry
$this->getHttp()->addMiddleware(Middleware::retry(function ($retries, RequestInterface $request, ResponseInterface $response = null, RequestException $exception = null) {
// Limit the number of retries to 2
if ($retries <= 2 && $response && ($body = $response->getBody())) {
// Retry on server errors
if (stripos($body, 'errcode') && (stripos($body, '40001') || stripos($body, '42001'))) {
return true;
}
}
return false;
}));
}
示例12: readStreamFeed
/**
* @param string $streamUrl
* @param EntryEmbedMode $embedMode
* @return StreamFeed
* @throws Exception\StreamDeletedException
* @throws Exception\StreamNotFoundException
*/
private function readStreamFeed($streamUrl, EntryEmbedMode $embedMode = null)
{
$request = $this->getJsonRequest($streamUrl);
if ($embedMode != null && $embedMode != EntryEmbedMode::NONE()) {
$uri = Uri::withQueryValue($request->getUri(), 'embed', $embedMode->toNative());
$request = $request->withUri($uri);
}
$this->sendRequest($request);
$this->ensureStatusCodeIsGood($streamUrl);
return new StreamFeed($this->lastResponseAsJson(), $embedMode);
}
示例13: configureAuthenticationHandler
private function configureAuthenticationHandler(HandlerStack $handlerStack)
{
$token = $this->token;
$handlerStack->remove('wechatClient:authentication');
$handlerStack->unshift(function (callable $handler) use($token) {
return function (RequestInterface $request, array $options = []) use($handler, $token) {
if ($token) {
$newUri = Uri::withQueryValue($request->getUri(), 'access_token', $token->value());
$request = $request->withUri($newUri);
}
return $handler($request, $options);
};
}, 'wechatClient:authentication');
}
示例14: createRequest
/**
* Creates a new Request to this Endpoint.
*
* @param string[] $query
* @param null $url
* @param string $method
* @param array $options
* @return RequestInterface
*/
protected function createRequest(array $query = [], $url = null, $method = 'GET', $options = [])
{
$url = !is_null($url) ? $url : $this->url();
$uri = new Uri($url);
foreach ($query as $key => $value) {
$uri = Uri::withQueryValue($uri, $key, $value);
}
return new Request($method, $uri, $options);
}
示例15: httpGet
/**
* Performs a GET against the API.
*
* @param string $path
* @param array $query
*
* @return ResponseInterface
* @throw Exception\PostcodeException | Exception\ApiException | Exception\UnexpectedValueException
*/
private function httpGet($path, array $query = array())
{
$url = new Uri($this->baseUrl . $path);
foreach ($query as $name => $value) {
$url = Uri::withQueryValue($url, $name, $value);
}
//---
$request = new Request('GET', $url, $this->buildHeaders());
try {
$response = $this->getHttpClient()->sendRequest($request);
} catch (\RuntimeException $e) {
throw new Exception\PostcodeException($e->getMessage(), $e->getCode(), $e);
}
//---
if ($response->getStatusCode() != 200) {
throw $this->createErrorException($response);
}
return $response;
}