‪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\DependencyInjection\Attribute\Autoconfigure;
23 use Symfony\Component\Routing\RequestContext;
25 
30 #[Autoconfigure(public: true)]
32 {
33  public function ‪__construct(
34  protected readonly ‪BackendEntryPointResolver $backendEntryPointResolver
35  ) {}
36 
37  public function ‪fromBackendRequest(ServerRequestInterface $request): RequestContext
38  {
39  $scheme = $request->getUri()->getScheme();
40  return new RequestContext(
41  $this->backendEntryPointResolver->getPathFromRequest($request),
42  $request->getMethod(),
43  (string)idn_to_ascii($request->getUri()->getHost()),
44  $request->getUri()->getScheme(),
45  $scheme === 'http' ? $request->getUri()->getPort() ?? 80 : 80,
46  $scheme === 'https' ? $request->getUri()->getPort() ?? 443 : 443,
47  );
48  }
49 
50  public function ‪fromUri(UriInterface $uri, string $method = 'GET'): RequestContext
51  {
52  return new RequestContext(
53  '',
54  $method,
55  (string)idn_to_ascii($uri->getHost()),
56  $uri->getScheme(),
57  // Ports are only necessary for URL generation in Symfony which is not used by TYPO3
58  80,
59  443,
60  $uri->getPath()
61  );
62  }
63 
64  public function ‪fromSiteLanguage(‪SiteLanguage $language): RequestContext
65  {
66  $scheme = $language->‪getBase()->getScheme();
67  return new RequestContext(
68  // page segment (slug & enhanced part) is supposed to start with '/'
69  rtrim($language->‪getBase()->getPath(), '/'),
70  'GET',
71  $language->‪getBase()->getHost(),
72  $scheme ?: 'https',
73  $scheme === 'http' ? $language->‪getBase()->getPort() ?? 80 : 80,
74  $scheme === 'https' ? $language->‪getBase()->getPort() ?? 443 : 443
75  );
76  }
77 }
‪TYPO3\CMS\Core\Routing\RequestContextFactory\fromUri
‪fromUri(UriInterface $uri, string $method='GET')
Definition: RequestContextFactory.php:50
‪TYPO3\CMS\Core\Routing\RequestContextFactory\fromSiteLanguage
‪fromSiteLanguage(SiteLanguage $language)
Definition: RequestContextFactory.php:64
‪TYPO3\CMS\Core\Routing\RequestContextFactory\__construct
‪__construct(protected readonly BackendEntryPointResolver $backendEntryPointResolver)
Definition: RequestContextFactory.php:33
‪TYPO3\CMS\Core\Routing\RequestContextFactory\fromBackendRequest
‪fromBackendRequest(ServerRequestInterface $request)
Definition: RequestContextFactory.php:37
‪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:31
‪TYPO3\CMS\Core\Routing\RequestContextFactory
Definition: RequestContextFactory.php:32