‪TYPO3CMS  ‪main
RequestContextFactory.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ServerRequestInterface;
21 use Psr\Http\Message\UriInterface;
22 use Symfony\Component\Routing\RequestContext;
24 
30 {
31  public function ‪__construct(
32  protected readonly ‪BackendEntryPointResolver $backendEntryPointResolver
33  ) {}
34 
35  public function ‪fromBackendRequest(ServerRequestInterface $request): RequestContext
36  {
37  $scheme = $request->getUri()->getScheme();
38  return new RequestContext(
39  $this->backendEntryPointResolver->getPathFromRequest($request),
40  $request->getMethod(),
41  (string)idn_to_ascii($request->getUri()->getHost()),
42  $request->getUri()->getScheme(),
43  $scheme === 'http' ? $request->getUri()->getPort() ?? 80 : 80,
44  $scheme === 'https' ? $request->getUri()->getPort() ?? 443 : 443,
45  );
46  }
47 
48  public function ‪fromUri(UriInterface $uri, string $method = 'GET'): RequestContext
49  {
50  return new RequestContext(
51  '',
52  $method,
53  (string)idn_to_ascii($uri->getHost()),
54  $uri->getScheme(),
55  // Ports are only necessary for URL generation in Symfony which is not used by TYPO3
56  80,
57  443,
58  $uri->getPath()
59  );
60  }
61 
62  public function ‪fromSiteLanguage(‪SiteLanguage $language): RequestContext
63  {
64  $scheme = $language->‪getBase()->getScheme();
65  return new RequestContext(
66  // page segment (slug & enhanced part) is supposed to start with '/'
67  rtrim($language->‪getBase()->getPath(), '/'),
68  'GET',
69  $language->‪getBase()->getHost(),
70  $scheme ?: 'https',
71  $scheme === 'http' ? $language->‪getBase()->getPort() ?? 80 : 80,
72  $scheme === 'https' ? $language->‪getBase()->getPort() ?? 443 : 443
73  );
74  }
75 }
‪TYPO3\CMS\Core\Routing\RequestContextFactory\fromUri
‪fromUri(UriInterface $uri, string $method='GET')
Definition: RequestContextFactory.php:48
‪TYPO3\CMS\Core\Routing\RequestContextFactory\fromSiteLanguage
‪fromSiteLanguage(SiteLanguage $language)
Definition: RequestContextFactory.php:62
‪TYPO3\CMS\Core\Routing\RequestContextFactory\__construct
‪__construct(protected readonly BackendEntryPointResolver $backendEntryPointResolver)
Definition: RequestContextFactory.php:31
‪TYPO3\CMS\Core\Routing\RequestContextFactory\fromBackendRequest
‪fromBackendRequest(ServerRequestInterface $request)
Definition: RequestContextFactory.php:35
‪TYPO3\CMS\Core\Routing
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage
Definition: SiteLanguage.php:27
‪TYPO3\CMS\Core\Site\Entity\SiteLanguage\getBase
‪getBase()
Definition: SiteLanguage.php:179
‪TYPO3\CMS\Core\Routing\BackendEntryPointResolver
Definition: BackendEntryPointResolver.php:29
‪TYPO3\CMS\Core\Routing\RequestContextFactory
Definition: RequestContextFactory.php:30