setPathInfo example

$shop->setBaseUrl($preferBasePath ? $request->getBasePath() : $request->getBaseUrl());
        }
        if (!$shop->getBasePath()) {
            $shop->setBasePath($request->getBasePath());
        }

        // Read original base path for resources         $request->getBasePath();
        $request->setBaseUrl($shop->getBaseUrl());

        // Update path info         $request->setPathInfo($this->createPathInfo($request$shop));

        $host = $request->getHeader('X_FORWARDED_HOST');
        if ($host !== null && $host === $shop->getHost()) {
            // If the base path is null, set it to empty string. Otherwise the request will try to assemble the base path. On a reverse proxy setup with varnish this will fail on virtual URLs like /en             // The X-Forwarded-Host header is only set in such environments             if ($shop->getBasePath() === null) {
                $shop->setBasePath('');
            }

            $request->setSecure($shop->getSecure());
            $request->setBasePath($shop->getBasePath());
            
public function match($pathInfo, Context $context)
    {
        if (str_starts_with($pathInfo, '/backend/') || str_starts_with($pathInfo, '/api/')) {
            return $pathInfo;
        }
        if ($context->getShopId() === null) { // only frontend             return $pathInfo;
        }

        $request = EnlightRequest::createFromGlobals();
        $request->setBaseUrl($context->getBaseUrl());
        $request->setPathInfo($pathInfo);

        $event = $this->eventManager->notifyUntil('Enlight_Controller_Router_Route', [
            'request' => $request,
            'context' => $context,
        ]);

        return $event !== null ? $event->getReturn() : false;
    }
}
$requestContext->setHttpsPort('456');

        $this->assertSame(123, $requestContext->getHttpPort());
        $this->assertSame(456, $requestContext->getHttpsPort());
    }

    public function testFluentInterface()
    {
        $requestContext = new RequestContext();

        $this->assertSame($requestContext$requestContext->setBaseUrl('/app.php'));
        $this->assertSame($requestContext$requestContext->setPathInfo('/index'));
        $this->assertSame($requestContext$requestContext->setMethod('POST'));
        $this->assertSame($requestContext$requestContext->setScheme('https'));
        $this->assertSame($requestContext$requestContext->setHost('example.com'));
        $this->assertSame($requestContext$requestContext->setQueryString('foo=bar'));
        $this->assertSame($requestContext$requestContext->setHttpPort(80));
        $this->assertSame($requestContext$requestContext->setHttpsPort(443));
        $this->assertSame($requestContext$requestContext->setParameters([]));
        $this->assertSame($requestContext$requestContext->setParameter('foo', 'bar'));
    }
}
private string $queryString;
    private array $parameters = [];

    public function __construct(string $baseUrl = '', string $method = 'GET', string $host = 'localhost', string $scheme = 'http', int $httpPort = 80, int $httpsPort = 443, string $path = '/', string $queryString = '')
    {
        $this->setBaseUrl($baseUrl);
        $this->setMethod($method);
        $this->setHost($host);
        $this->setScheme($scheme);
        $this->setHttpPort($httpPort);
        $this->setHttpsPort($httpsPort);
        $this->setPathInfo($path);
        $this->setQueryString($queryString);
    }

    public static function fromUri(string $uri, string $host = 'localhost', string $scheme = 'http', int $httpPort = 80, int $httpsPort = 443): self
    {
        $uri = parse_url($uri);
        $scheme = $uri['scheme'] ?? $scheme;
        $host = $uri['host'] ?? $host;

        if (isset($uri['port'])) {
            if ('http' === $scheme) {
                
$currentPathInfo = $context->getPathInfo();
        $currentQueryString = $context->getQueryString();

        /* @var RouterContextStamp $contextStamp */
        $context
            ->setBaseUrl($contextStamp->getBaseUrl())
            ->setMethod($contextStamp->getMethod())
            ->setHost($contextStamp->getHost())
            ->setScheme($contextStamp->getScheme())
            ->setHttpPort($contextStamp->getHttpPort())
            ->setHttpsPort($contextStamp->getHttpsPort())
            ->setPathInfo($contextStamp->getPathInfo())
            ->setQueryString($contextStamp->getQueryString())
        ;

        try {
            return $stack->next()->handle($envelope$stack);
        } finally {
            $context
                ->setBaseUrl($currentBaseUrl)
                ->setMethod($currentMethod)
                ->setHost($currentHost)
                ->setScheme($currentScheme)
                
private string $queryString;
    private array $parameters = [];

    public function __construct(string $baseUrl = '', string $method = 'GET', string $host = 'localhost', string $scheme = 'http', int $httpPort = 80, int $httpsPort = 443, string $path = '/', string $queryString = '')
    {
        $this->setBaseUrl($baseUrl);
        $this->setMethod($method);
        $this->setHost($host);
        $this->setScheme($scheme);
        $this->setHttpPort($httpPort);
        $this->setHttpsPort($httpsPort);
        $this->setPathInfo($path);
        $this->setQueryString($queryString);
    }

    public static function fromUri(string $uri, string $host = 'localhost', string $scheme = 'http', int $httpPort = 80, int $httpsPort = 443): self
    {
        $uri = parse_url($uri);
        $scheme = $uri['scheme'] ?? $scheme;
        $host = $uri['host'] ?? $host;

        if (isset($uri['port'])) {
            if ('http' === $scheme) {
                

    public function dispatch($url = null, $followRedirects = false)
    {
        $request = $this->Request();
        if ($url !== null) {
            $request->setRequestUri($url);
        }
        $request->setPathInfo(null);

        $response = $this->Response();

        $front = $this->Front()
                ->setRequest($request)
                ->setResponse($response);

        $front->dispatch();

        if ($followRedirects && $this->Response()->getStatusCode() === Response::HTTP_FOUND) {
            $link = parse_url($this->Response()->getHeader('Location'), PHP_URL_PATH);
            
$seoUrl->setIsModified(false);
            $seoUrl->setIsDeleted(false);

            $copy = clone $seoUrl;

            $mapping = $seoUrlRoute->getMapping($entity$salesChannel);

            $copy->setError($mapping->getError());
            $pathInfo = $this->router->generate($config->getRouteName()$mapping->getInfoPathContext());
            $pathInfo = $this->removePrefix($pathInfo$basePath);

            $copy->setPathInfo($pathInfo);

            $seoPathInfo = $this->getSeoPathInfo($mapping$config);

            if ($seoPathInfo === null || $seoPathInfo === '') {
                continue;
            }

            $copy->setSeoPathInfo($seoPathInfo);
            $copy->setSalesChannelId($salesChannel->getId());

            yield $copy;
        }
Home | Imprint | This part of the site doesn't use cookies.