本文整理汇总了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());
}
示例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());
}
示例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'));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}