setHttpPort example

private int $httpPort;
    private int $httpsPort;
    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;

        
$currentHttpPort = $context->getHttpPort();
        $currentHttpsPort = $context->getHttpsPort();
        $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)
                
$this->requestStack = $this->createMock(RequestStack::class);
    }

    /** * @dataProvider getPortData */
    public function testPort($defaultHttpPort$defaultHttpsPort$uri$expectedHttpPort$expectedHttpsPort)
    {
        $urlMatcher = $this->createMock(UrlMatcherInterface::class);

        $context = new RequestContext();
        $context->setHttpPort($defaultHttpPort);
        $context->setHttpsPort($defaultHttpsPort);
        $urlMatcher->expects($this->any())
            ->method('getContext')
            ->willReturn($context);

        $listener = new RouterListener($urlMatcher$this->requestStack);
        $event = $this->createRequestEventForUri($uri);
        $listener->onKernelRequest($event);

        $this->assertEquals($expectedHttpPort$context->getHttpPort());
        $this->assertEquals($expectedHttpsPort$context->getHttpsPort());
        
$this->assertSame('http', $requestContext->getScheme());
        $this->assertSame('localhost', $requestContext->getHost());
        $this->assertSame('', $requestContext->getBaseUrl());
        $this->assertSame('/', $requestContext->getPathInfo());
    }

    public function testFromRequest()
    {
        $request = Request::create('https://test.com:444/foo?bar=baz');
        $requestContext = new RequestContext();
        $requestContext->setHttpPort(123);
        $requestContext->fromRequest($request);

        $this->assertEquals('', $requestContext->getBaseUrl());
        $this->assertEquals('GET', $requestContext->getMethod());
        $this->assertEquals('test.com', $requestContext->getHost());
        $this->assertEquals('https', $requestContext->getScheme());
        $this->assertEquals('/foo', $requestContext->getPathInfo());
        $this->assertEquals('bar=baz', $requestContext->getQueryString());
        $this->assertSame(123, $requestContext->getHttpPort());
        $this->assertSame(444, $requestContext->getHttpsPort());

        
private int $httpPort;
    private int $httpsPort;
    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;

        

        $parsedUrl = parse_url($newTokenResponse->getRedirectUrl());

        if (!$parsedUrl) {
            throw RoutingException::languageNotFound($languageId);
        }

        $routerContext = $this->router->getContext();
        $routerContext->setHttpPort($parsedUrl['port'] ?? 80);
        $routerContext->setMethod('GET');
        $routerContext->setHost($parsedUrl['host']);
        $routerContext->setBaseUrl(rtrim($parsedUrl['path'] ?? '', '/'));

        if ($this->requestStack->getMainRequest()) {
            $this->requestStack->getMainRequest()
                ->attributes->set(RequestTransformer::SALES_CHANNEL_BASE_URL, '');
        }

        $url = $this->router->generate($route$params, Router::ABSOLUTE_URL);

        
Home | Imprint | This part of the site doesn't use cookies.