TYPO3  7.6
extbase/Classes/Mvc/Web/Request.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extbase\Mvc\Web;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 {
27  protected $hashService;
28 
32  protected $format = 'html';
33 
37  protected $method = 'GET';
38 
42  protected $requestUri;
43 
47  protected $baseUri;
48 
52  protected $isCached = false;
53 
58 
63 
67  public function injectHashService(\TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService)
68  {
69  $this->hashService = $hashService;
70  }
71 
75  public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
76  {
77  $this->configurationManager = $configurationManager;
78  }
79 
83  public function injectEnvironmentService(\TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService)
84  {
85  $this->environmentService = $environmentService;
86  }
87 
95  public function setMethod($method)
96  {
97  if ($method === '' || strtoupper($method) !== $method) {
98  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidRequestMethodException('The request method "' . $method . '" is not supported.', 1217778382);
99  }
100  $this->method = $method;
101  }
102 
109  public function getMethod()
110  {
111  return $this->method;
112  }
113 
120  public function setRequestUri($requestUri)
121  {
122  $this->requestUri = $requestUri;
123  }
124 
131  public function getRequestUri()
132  {
133  return $this->requestUri;
134  }
135 
142  public function setBaseUri($baseUri)
143  {
144  $this->baseUri = $baseUri;
145  }
146 
153  public function getBaseUri()
154  {
155  if ($this->environmentService->isEnvironmentInBackendMode()) {
156  return $this->baseUri . TYPO3_mainDir;
157  } else {
158  return $this->baseUri;
159  }
160  }
161 
167  public function setIsCached($isCached)
168  {
169  $this->isCached = (bool)$isCached;
170  }
171 
178  public function isCached()
179  {
180  return $this->isCached;
181  }
182 
188  public function getReferringRequest()
189  {
190  if (isset($this->internalArguments['__referrer']) && is_array($this->internalArguments['__referrer'])) {
191  $referrerArray = $this->internalArguments['__referrer'];
192  $referringRequest = new \TYPO3\CMS\Extbase\Mvc\Web\Request();
193  $arguments = array();
194  if (isset($referrerArray['arguments'])) {
195  $serializedArgumentsWithHmac = $referrerArray['arguments'];
196  $serializedArguments = $this->hashService->validateAndStripHmac($serializedArgumentsWithHmac);
197  $arguments = unserialize(base64_decode($serializedArguments));
198  unset($referrerArray['arguments']);
199  }
200  $referringRequest->setArguments(\TYPO3\CMS\Extbase\Utility\ArrayUtility::arrayMergeRecursiveOverrule($arguments, $referrerArray));
201  return $referringRequest;
202  }
203  return null;
204  }
205 }