af72b652704aa09c294960a0468d17a385b19e5d
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / ExpressionLanguage / RequestWrapper.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\ExpressionLanguage;
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
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Core\Http\NormalizedParams;
20 use TYPO3\CMS\Core\Http\ServerRequest;
21 use TYPO3\CMS\Core\Site\Entity\SiteInterface;
22 use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
23
24 /**
25 * Class RequestWrapper
26 * This class provides access to some methods of the ServerRequest object.
27 * To prevent access to all methods of the ServerRequest object within conditions,
28 * this class was introduced to control which methods are exposed.
29 *
30 * Additionally this class can be used to simulate a request for condition matching in case the condition matcher calls
31 * should be simulated (for example simulating parsing of TypoScript on CLI)
32 * @internal
33 */
34 class RequestWrapper
35 {
36 /**
37 * @var ServerRequestInterface
38 */
39 protected $request;
40
41 public function __construct(?ServerRequestInterface $request)
42 {
43 $this->request = $request ?? new ServerRequest();
44 }
45
46 public function getQueryParams(): array
47 {
48 return $this->request->getQueryParams();
49 }
50
51 public function getParsedBody()
52 {
53 return $this->request->getParsedBody();
54 }
55
56 public function getHeaders(): array
57 {
58 return $this->request->getHeaders();
59 }
60
61 public function getCookieParams(): array
62 {
63 return $this->request->getCookieParams();
64 }
65
66 public function getSite(): ?SiteInterface
67 {
68 return $this->request->getAttribute('site');
69 }
70
71 public function getSiteLanguage(): ?SiteLanguage
72 {
73 return $this->request->getAttribute('language');
74 }
75
76 public function getNormalizedParams(): ?NormalizedParams
77 {
78 return $this->request->getAttribute('normalizedParams');
79 }
80 }