本文整理汇总了PHP中Psr\Http\Message\ServerRequestInterface::withUri方法的典型用法代码示例。如果您正苦于以下问题:PHP ServerRequestInterface::withUri方法的具体用法?PHP ServerRequestInterface::withUri怎么用?PHP ServerRequestInterface::withUri使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\ServerRequestInterface
的用法示例。
在下文中一共展示了ServerRequestInterface::withUri方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addLanguage
public function addLanguage(ServerRequestInterface $request, $language)
{
$path = $request->getUri()->getPath();
if ($language !== $this->environment->getDefaultLanguage()) {
$path = '/' . $language . ($path === '/' ? '' : $path);
}
return $request->withUri($request->getUri()->withPath($path));
}
示例2: guess
/**
* Guesses the base URI of the application.
*
* @param Psr\Http\Message\ServerRequestInterface $request
* @return Psr\Http\Message\ServerRequestInterface
*/
public static function guess(\Psr\Http\Message\ServerRequestInterface $request)
{
$server = $request->getServerParams();
$basename = basename($server['SCRIPT_FILENAME']);
$position = strpos($server['SCRIPT_NAME'], $basename) - 1;
$rootUri = substr($server['SCRIPT_NAME'], 0, $position);
$oldPath = $request->getUri()->getPath();
$newPath = str_replace($rootUri, '', $oldPath);
$uri = $request->getUri()->withPath($newPath);
return $request->withUri($uri);
}
示例3: updatePath
/**
* Updates the request URI to remove the base directory.
*
* @param string $base The base path to remove.
* @param \Psr\Http\Message\ServerRequestInterface $request The request to modify.
* @return \Psr\Http\Message\ServerRequestInterface The modified request.
*/
protected static function updatePath($base, $request)
{
$uri = $request->getUri();
$path = $uri->getPath();
if (strlen($base) > 0 && strpos($path, $base) === 0) {
$path = substr($path, strlen($base));
}
if (empty($path) || $path === '/' || $path === '//' || $path === '/index.php') {
$path = '/';
}
$endsWithIndex = '/webroot/index.php';
$endsWithLength = strlen($endsWithIndex);
if (strlen($path) >= $endsWithLength && substr($path, -$endsWithLength) === $endsWithIndex) {
$path = '/';
}
return $request->withUri($uri->withPath($path));
}
示例4: convertToProxiedRequest
/**
* @return \Psr\Http\Message\RequestInterface
*/
public function convertToProxiedRequest()
{
$proxiedUri = $this->request->getUri()->withScheme($this->proxyUri->getScheme())->withHost($this->proxyUri->getHost())->withPath(rtrim($this->proxyUri->getPath(), '/') . $this->request->getUri()->getPath());
if ($this->proxyUri->getPort() != null) {
$proxiedUri = $proxiedUri->withPort($this->proxyUri->getPort());
} else {
$proxiedUri = $proxiedUri->withPort($proxiedUri->getScheme() === "https" ? 443 : 80);
}
$proxiedRequest = $this->request->withUri($proxiedUri)->withHeader("host", $this->proxyUri->getHost());
if ($proxiedRequest->getBody()->getSize() === null && $proxiedRequest->getHeaderLine("User-Agent") == "Http_TestCase/1.0") {
// FIXME
// Prevents an incompatibility with PHP-VCR :
// Without this the stream size is null and not 0 so CurlFactory#applyBody is applied and it sets a
// CURLOPT_READFUNCTION on the request, but not a CURLOPT_INFILESIZE ; which makes VCR fails.
// See https://github.com/guzzle/guzzle/commit/0a3065ea4639c1df8b9220bc8ca3fb529d7f8b52#commitcomment-12551295
$proxiedRequest = $proxiedRequest->withBody(\GuzzleHttp\Psr7\stream_for());
}
return $proxiedRequest;
}
示例5: withUri
/**
* {@inheritdoc}
*/
public function withUri(UriInterface $uri, $preserveHost = false)
{
return new static($this->wrapped->withUri($uri, $preserveHost));
}
示例6: withUri
/**
* {@inheritDoc}
*/
public function withUri(UriInterface $uri, $preserveHost = false)
{
return new self($this->app, $this->psrRequest->withUri($uri, $preserveHost));
}
示例7: __invoke
/**
* Execute the middleware.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable $next
*
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
return $next($request->withUri(self::getRealUri($request), true), $response);
}
示例8: stripRouteFromPath
/**
* Strip the route from the request path
*
* @param ServerRequestInterface $request
* @param string $route
* @return ServerRequestInterface
*/
private function stripRouteFromPath(ServerRequestInterface $request, $route)
{
$this->removed = $route;
$uri = $request->getUri();
$path = $this->getTruncatedPath($route, $uri->getPath());
$new = $uri->withPath($path);
// Root path of route is treated differently
if ($path === '/' && '/' === substr($uri->getPath(), -1)) {
$this->removed .= '/';
}
return $request->withUri($new);
}
示例9: withUri
/**
* Allow mutating the URI
*
* {@inheritdoc}
*/
public function withUri(UriInterface $uri, $preserveHost = false)
{
$new = $this->psrRequest->withUri($uri, $preserveHost);
return new self($new, $this->originalRequest);
}
示例10: filterRequest
/**
* Filters the request base URI to filter development and debugging stuff.
*
* @param Request $request Request to be filtered
* @param array|\stdClass $filters ArrayAccess filters
*
* @author Benjamin Carl <opensource@clickalicious.de>
*
* @return Request Filtered and prepared request instance
* @static
*/
protected static function filterRequest(Request $request, $filters)
{
$tmp = [];
foreach ($filters as $filter) {
$tmp[] = $filter;
}
$filter = new \Doozr_Filter($tmp);
return $request->withUri($request->getUri()->withPath($filter->apply($request->getUri()->getPath())));
}
示例11: withUri
/**
* @inheritDoc
*/
public function withUri(UriInterface $uri, $preserveHost = false)
{
$self = clone $this;
$self->serverRequest = $this->serverRequest->withUri($uri, $preserveHost);
return $self;
}