73a1ae11910a1108a1bacff552a4284b2b70c5e9
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Mvc / Web / Request.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Mvc\Web;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
8 * Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * Represents a web request.
32 *
33 * @api
34 */
35 class Request extends \TYPO3\CMS\Extbase\Mvc\Request {
36
37 /**
38 * @var \TYPO3\CMS\Extbase\Security\Cryptography\HashService
39 */
40 protected $hashService;
41
42 /**
43 * @var string The requested representation format
44 */
45 protected $format = 'html';
46
47 /**
48 * @var string Contains the request method
49 */
50 protected $method = 'GET';
51
52 /**
53 * @var string
54 */
55 protected $requestUri;
56
57 /**
58 * @var string The base URI for this request - ie. the host and path leading to the index.php
59 */
60 protected $baseUri;
61
62 /**
63 * @var boolean TRUE if the HMAC of this request could be verified, FALSE otherwise
64 * @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
65 */
66 protected $hmacVerified = FALSE;
67
68 /**
69 * @var boolean TRUE if the current request is cached, false otherwise.
70 */
71 protected $isCached = FALSE;
72
73 /**
74 * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
75 */
76 protected $configurationManager;
77
78 /**
79 * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
80 */
81 protected $environmentService;
82
83 /**
84 * @param \TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService
85 */
86 public function injectHashService(\TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService) {
87 $this->hashService = $hashService;
88 }
89
90 /**
91 * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
92 * @return void
93 */
94 public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager) {
95 $this->configurationManager = $configurationManager;
96 }
97
98 /**
99 * @param \TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService
100 *
101 * @return void
102 */
103 public function injectEnvironmentService(\TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService) {
104 $this->environmentService = $environmentService;
105 }
106
107 /**
108 * Sets the request method
109 *
110 * @param string $method Name of the request method
111 * @return void
112 * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidRequestMethodException if the request method is not supported
113 */
114 public function setMethod($method) {
115 if ($method === '' || strtoupper($method) !== $method) {
116 throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidRequestMethodException('The request method "' . $method . '" is not supported.', 1217778382);
117 }
118 $this->method = $method;
119 }
120
121 /**
122 * Returns the name of the request method
123 *
124 * @return string Name of the request method
125 * @api
126 */
127 public function getMethod() {
128 return $this->method;
129 }
130
131 /**
132 * Sets the request URI
133 *
134 * @param string $requestUri URI of this web request
135 * @return void
136 */
137 public function setRequestUri($requestUri) {
138 $this->requestUri = $requestUri;
139 }
140
141 /**
142 * Returns the request URI
143 *
144 * @return string URI of this web request
145 * @api
146 */
147 public function getRequestUri() {
148 return $this->requestUri;
149 }
150
151 /**
152 * Sets the base URI for this request.
153 *
154 * @param string $baseUri New base URI
155 * @return void
156 */
157 public function setBaseUri($baseUri) {
158 $this->baseUri = $baseUri;
159 }
160
161 /**
162 * Returns the base URI
163 *
164 * @return string Base URI of this web request
165 * @api
166 */
167 public function getBaseUri() {
168 if ($this->environmentService->isEnvironmentInBackendMode()) {
169 return $this->baseUri . TYPO3_mainDir;
170 } else {
171 return $this->baseUri;
172 }
173 }
174
175 /**
176 * Could the request be verified via a HMAC?
177 *
178 * @param boolean $hmacVerified TRUE if request could be verified, FALSE otherwise
179 * @return void
180 * @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
181 */
182 public function setHmacVerified($hmacVerified) {
183 $this->hmacVerified = (boolean) $hmacVerified;
184 }
185
186 /**
187 * Could the request be verified via a HMAC?
188 *
189 * @return boolean TRUE if request could be verified, FALSE otherwise
190 * @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
191 */
192 public function isHmacVerified() {
193 return $this->hmacVerified;
194 }
195
196 /**
197 * Set if the current request is cached.
198 *
199 * @param boolean $isCached
200 */
201 public function setIsCached($isCached) {
202 $this->isCached = (boolean) $isCached;
203 }
204
205 /**
206 * Return whether the current request is a cached request or not.
207 *
208 * @api (v4 only)
209 * @return boolean the caching status.
210 */
211 public function isCached() {
212 return $this->isCached;
213 }
214
215 /**
216 * Get a freshly built request object pointing to the Referrer.
217 *
218 * @return Request the referring request, or NULL if no referrer found
219 */
220 public function getReferringRequest() {
221 if (isset($this->internalArguments['__referrer']) && is_array($this->internalArguments['__referrer'])) {
222 $referrerArray = $this->internalArguments['__referrer'];
223 $referringRequest = new \TYPO3\CMS\Extbase\Mvc\Web\Request();
224 $arguments = array();
225 if (isset($referrerArray['arguments'])) {
226 $serializedArgumentsWithHmac = $referrerArray['arguments'];
227 $serializedArguments = $this->hashService->validateAndStripHmac($serializedArgumentsWithHmac);
228 $arguments = unserialize(base64_decode($serializedArguments));
229 unset($referrerArray['arguments']);
230 }
231 $referringRequest->setArguments(\TYPO3\CMS\Extbase\Utility\ArrayUtility::arrayMergeRecursiveOverrule($arguments, $referrerArray));
232 return $referringRequest;
233 }
234 return NULL;
235 }
236 }
237
238 ?>