当前位置: 首页>>代码示例>>PHP>>正文


PHP RequestInterface::withUri方法代码示例

本文整理汇总了PHP中Psr\Http\Message\RequestInterface::withUri方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::withUri方法的具体用法?PHP RequestInterface::withUri怎么用?PHP RequestInterface::withUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Psr\Http\Message\RequestInterface的用法示例。


在下文中一共展示了RequestInterface::withUri方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: to

 /**
  * Forward the request to the target url and return the response.
  *
  * @param  string $target
  * @throws UnexpectedValueException
  * @return Response
  */
 public function to($target)
 {
     if (is_null($this->request)) {
         throw new UnexpectedValueException('Missing request instance.');
     }
     $target = new Uri($target);
     // Overwrite target scheme and host.
     $uri = $this->request->getUri()->withScheme($target->getScheme())->withHost($target->getHost());
     // Check for custom port.
     if ($port = $target->getPort()) {
         $uri = $uri->withPort($port);
     }
     // Check for subdirectory.
     if ($path = $target->getPath()) {
         $uri = $uri->withPath(rtrim($path, '/') . '/' . ltrim($uri->getPath(), '/'));
     }
     $request = $this->request->withUri($uri);
     $stack = $this->filters;
     $stack[] = function (RequestInterface $request, ResponseInterface $response, callable $next) {
         $response = $this->adapter->send($request);
         return $next($request, $response);
     };
     $relay = (new RelayBuilder())->newInstance($stack);
     return $relay($request, new Response());
 }
开发者ID:kangkot,项目名称:php-proxy,代码行数:32,代码来源:Proxy.php

示例2: to

 /**
  * Forward the request to the target url and return the response.
  *
  * @param  string $target
  * @throws UnexpectedValueException
  * @return Response
  */
 public function to($target)
 {
     if (is_null($this->request)) {
         throw new UnexpectedValueException('Missing request instance.');
     }
     $uri = $this->request->getUri()->withScheme(parse_url($target, PHP_URL_SCHEME))->withHost(parse_url($target, PHP_URL_HOST));
     $request = $this->request->withUri($uri);
     $stack = $this->filters;
     $stack[] = function (RequestInterface $request, ResponseInterface $response, callable $next) use($target) {
         $response = $this->adapter->send($request, $target);
         return $next($request, $response);
     };
     $relay = (new RelayBuilder())->newInstance($stack);
     return $relay($request, new Response());
 }
开发者ID:allantatter,项目名称:php-proxy,代码行数:22,代码来源:Proxy.php

示例3: testWithUriTrue

 public function testWithUriTrue()
 {
     /**
      * You can opt-in to preserving the original state of the Host header by
      * setting `$preserveHost` to `true`. When `$preserveHost` is set to
      * `true`, this method interacts with the Host header in the following ways:
      *
      * - If the the Host header is missing or empty, and the new URI contains
      *   a host component, this method MUST update the Host header in the returned
      *   request.
      * - If the Host header is missing or empty, and the new URI does not contain a
      *   host component, this method MUST NOT update the Host header in the returned
      *   request.
      * - If a Host header is present and non-empty, this method MUST NOT update
      *   the Host header in the returned request.
      */
     $mockUri = Mockery::mock(UriInterface::class);
     $mockUri->shouldReceive('getHost')->andReturn('localhost');
     $mockUri->shouldReceive('getPort')->andReturn(8888);
     $mockUri->shouldReceive('getPath')->andReturn('/');
     $mockUri->shouldReceive('getQuery')->andReturn('');
     $requestWithUri = $this->request->withUri($mockUri);
     $this->assertEquals('/', $requestWithUri->getRequestTarget());
     $this->assertEquals('localhost:8888', $requestWithUri->getHeaderLine('host'));
 }
开发者ID:Golpha,项目名称:Http,代码行数:25,代码来源:RequestTestTrait.php

示例4: authenticateRequest

 /**
  * Adds authentication credentials to given request.
  *
  * @param  RequestInterface  $request
  *
  * @return RequestInterface
  */
 protected function authenticateRequest(RequestInterface $request)
 {
     $uri = $request->getUri();
     parse_str($uri->getQuery(), $query);
     $query['key'] = Configuration::get('key');
     $query['token'] = Configuration::get('token');
     $uri = $uri->withQuery(http_build_query($query));
     return $request->withUri($uri);
 }
开发者ID:stevenmaguire,项目名称:trello-php,代码行数:16,代码来源:Http.php

示例5: addAuthentificationInfo

 /**
  * @param RequestInterface $request
  *
  * @return RequestInterface
  */
 public function addAuthentificationInfo(RequestInterface $request)
 {
     $uri = $request->getUri();
     $qs = $uri->getQuery();
     parse_str($qs, $query_data);
     $query_data[$this->param_name] = $this->value;
     $qs = http_build_query($query_data);
     $uri = $uri->withQuery($qs);
     return $request->withUri($uri);
 }
开发者ID:sc0rp10,项目名称:rest-client,代码行数:15,代码来源:QueryParameterProvider.php

示例6: transformToUploadUrl

 private function transformToUploadUrl()
 {
     $parts = parse_url((string) $this->request->getUri());
     if (!isset($parts['path'])) {
         $parts['path'] = '';
     }
     $parts['path'] = '/upload' . $parts['path'];
     $uri = Uri::fromParts($parts);
     $this->request = $this->request->withUri($uri);
 }
开发者ID:Devids,项目名称:google-api-php-client,代码行数:10,代码来源:MediaFileUpload.php

示例7: authenticate

 /**
  * {@inheritdoc}
  */
 public function authenticate(RequestInterface $request)
 {
     $uri = $request->getUri();
     $query = $uri->getQuery();
     $params = [];
     parse_str($query, $params);
     $params = array_merge($params, $this->params);
     $query = http_build_query($params);
     $uri = $uri->withQuery($query);
     return $request->withUri($uri);
 }
开发者ID:php-http,项目名称:message,代码行数:14,代码来源:QueryParam.php

示例8: modifyRequest

 private function modifyRequest(RequestInterface $request, CommandInterface $command)
 {
     $uri = $request->getUri();
     $path = $uri->getPath();
     $bucket = $command['Bucket'];
     $path = $this->removeBucketFromPath($path, $bucket);
     // Modify the Key to make sure the key is encoded, but slashes are not.
     if ($command['Key']) {
         $path = S3Client::encodeKey(rawurldecode($path));
     }
     return $request->withUri($uri->withPath($path));
 }
开发者ID:AWSRandall,项目名称:aws-sdk-php,代码行数:12,代码来源:BucketEndpointMiddleware.php

示例9: signRequest

 /**
  * @param RequestInterface $request
  * @param bool             $forceNew
  *
  * @return RequestInterface
  */
 public function signRequest(RequestInterface $request, $forceNew = false)
 {
     try {
         // force-get a new token if it was requested, if not, the regular
         // caching mechanism will be used so the call is not necessary here.
         if (true === $forceNew) {
             $this->pool->getToken($forceNew);
         }
         // create a new request with the new uri and the token added to the headers
         $uri = Uri::resolve(new Uri($this->pool->getEndpointUrl()), $request->getUri());
         return $request->withUri($uri)->withHeader('X-Auth-Token', $this->pool->getTokenId());
     } catch (TokenException $e) {
         throw new ClientException('Could not obtain token', $request, null, $e);
     }
 }
开发者ID:treehouselabs,项目名称:keystone-client,代码行数:21,代码来源:RequestSigner.php

示例10: __invoke

 /**
  * Execute the middleware.
  *
  * @param RequestInterface  $request
  * @param ResponseInterface $response
  * @param callable          $next
  *
  * @return ResponseInterface
  */
 public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
 {
     $uri = $request->getUri();
     $host = $uri->getHost();
     if ($this->addWww) {
         if ($this->canAddWww($host)) {
             $host = "www.{$host}";
         }
     } elseif (strpos($host, 'www.') === 0) {
         $host = substr($host, 4);
     }
     //redirect
     if (is_int($this->redirectStatus) && $uri->getHost() !== $host) {
         return self::getRedirectResponse($this->redirectStatus, $uri->withHost($host), $response);
     }
     return $next($request->withUri($uri->withHost($host)), $response);
 }
开发者ID:alexpts,项目名称:psr7-middlewares,代码行数:26,代码来源:Www.php

示例11: __invoke

 /**
  * Execute the middleware.
  *
  * @param RequestInterface  $request
  * @param ResponseInterface $response
  * @param callable          $next
  *
  * @return ResponseInterface
  */
 public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
 {
     $uri = $request->getUri();
     $path = $uri->getPath();
     if ($this->addSlash) {
         if (strlen($path) > 1 && substr($path, -1) !== '/' && !pathinfo($path, PATHINFO_EXTENSION)) {
             $path .= '/';
         }
     } else {
         if (strlen($path) > 1 && substr($path, -1) === '/') {
             $path = substr($path, 0, -1);
         }
     }
     //Ensure the path has one "/"
     if (empty($path) || $path === $this->basePath) {
         $path .= '/';
     }
     //redirect
     if (is_int($this->redirectStatus) && $uri->getPath() !== $path) {
         return self::getRedirectResponse($this->redirectStatus, $uri->withPath($path), $response);
     }
     return $next($request->withUri($uri->withPath($path)), $response);
 }
开发者ID:joe-meyer,项目名称:psr7-middlewares,代码行数:32,代码来源:TrailingSlash.php

示例12: withUri

 /**
  * @param UriInterface $uri
  * @param bool|false $preserveHost
  * @return RequestInterface
  */
 public function withUri(UriInterface $uri, $preserveHost = false)
 {
     $this->request = $this->request->withUri($uri, $preserveHost);
     return $this;
 }
开发者ID:bweston92,项目名称:expressive-async,代码行数:10,代码来源:ServerRequest.php

示例13: __invoke

 public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next = null)
 {
     $path = preg_replace('#^' . $this->location . '#', '', $request->getUri()->getPath());
     $uri = $request->getUri()->withPath($path);
     return $next($request->withUri($uri), $response);
 }
开发者ID:gamringer,项目名称:php-rest,代码行数:6,代码来源:RequestReroot.php

示例14: setQueryParams

 /**
  * @param array $params
  *
  * @return void
  * @author Mario Mueller
  */
 public function setQueryParams(array $params)
 {
     $uri = $this->guzzleRequest->getUri()->withQuery(\GuzzleHttp\Psr7\build_query($params));
     $this->guzzleRequest = $this->guzzleRequest->withUri($uri);
 }
开发者ID:GrizliK1988,项目名称:php-client,代码行数:11,代码来源:GuzzleTransportRequest.php

示例15: sendAsync

 public function sendAsync(RequestInterface $request, array $options = [])
 {
     // Merge the base URI into the request URI if needed.
     $options = $this->prepareDefaults($options);
     return $this->transfer($request->withUri($this->buildUri($request->getUri(), $options), $request->hasHeader('Host')), $options);
 }
开发者ID:sgtsaughter,项目名称:d8portfolio,代码行数:6,代码来源:Client.php


注:本文中的Psr\Http\Message\RequestInterface::withUri方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。