[TASK] Replace inject methods with @inject
[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 * @inject
40 */
41 protected $hashService;
42
43 /**
44 * @var string The requested representation format
45 */
46 protected $format = 'html';
47
48 /**
49 * @var string Contains the request method
50 */
51 protected $method = 'GET';
52
53 /**
54 * @var string
55 */
56 protected $requestUri;
57
58 /**
59 * @var string The base URI for this request - ie. the host and path leading to the index.php
60 */
61 protected $baseUri;
62
63 /**
64 * @var boolean TRUE if the HMAC of this request could be verified, FALSE otherwise
65 * @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
66 */
67 protected $hmacVerified = FALSE;
68
69 /**
70 * @var boolean TRUE if the current request is cached, false otherwise.
71 */
72 protected $isCached = FALSE;
73
74 /**
75 * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
76 * @inject
77 */
78 protected $configurationManager;
79
80 /**
81 * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
82 * @inject
83 */
84 protected $environmentService;
85
86 /**
87 * Sets the request method
88 *
89 * @param string $method Name of the request method
90 * @return void
91 * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidRequestMethodException if the request method is not supported
92 */
93 public function setMethod($method) {
94 if ($method === '' || strtoupper($method) !== $method) {
95 throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidRequestMethodException('The request method "' . $method . '" is not supported.', 1217778382);
96 }
97 $this->method = $method;
98 }
99
100 /**
101 * Returns the name of the request method
102 *
103 * @return string Name of the request method
104 * @api
105 */
106 public function getMethod() {
107 return $this->method;
108 }
109
110 /**
111 * Sets the request URI
112 *
113 * @param string $requestUri URI of this web request
114 * @return void
115 */
116 public function setRequestUri($requestUri) {
117 $this->requestUri = $requestUri;
118 }
119
120 /**
121 * Returns the request URI
122 *
123 * @return string URI of this web request
124 * @api
125 */
126 public function getRequestUri() {
127 return $this->requestUri;
128 }
129
130 /**
131 * Sets the base URI for this request.
132 *
133 * @param string $baseUri New base URI
134 * @return void
135 */
136 public function setBaseUri($baseUri) {
137 $this->baseUri = $baseUri;
138 }
139
140 /**
141 * Returns the base URI
142 *
143 * @return string Base URI of this web request
144 * @api
145 */
146 public function getBaseUri() {
147 if ($this->environmentService->isEnvironmentInBackendMode()) {
148 return $this->baseUri . TYPO3_mainDir;
149 } else {
150 return $this->baseUri;
151 }
152 }
153
154 /**
155 * Could the request be verified via a HMAC?
156 *
157 * @param boolean $hmacVerified TRUE if request could be verified, FALSE otherwise
158 * @return void
159 * @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
160 */
161 public function setHmacVerified($hmacVerified) {
162 $this->hmacVerified = (boolean) $hmacVerified;
163 }
164
165 /**
166 * Could the request be verified via a HMAC?
167 *
168 * @return boolean TRUE if request could be verified, FALSE otherwise
169 * @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
170 */
171 public function isHmacVerified() {
172 return $this->hmacVerified;
173 }
174
175 /**
176 * Set if the current request is cached.
177 *
178 * @param boolean $isCached
179 */
180 public function setIsCached($isCached) {
181 $this->isCached = (boolean) $isCached;
182 }
183
184 /**
185 * Return whether the current request is a cached request or not.
186 *
187 * @api (v4 only)
188 * @return boolean the caching status.
189 */
190 public function isCached() {
191 return $this->isCached;
192 }
193
194 /**
195 * Get a freshly built request object pointing to the Referrer.
196 *
197 * @return Request the referring request, or NULL if no referrer found
198 */
199 public function getReferringRequest() {
200 if (isset($this->internalArguments['__referrer']) && is_array($this->internalArguments['__referrer'])) {
201 $referrerArray = $this->internalArguments['__referrer'];
202 $referringRequest = new \TYPO3\CMS\Extbase\Mvc\Web\Request();
203 $arguments = array();
204 if (isset($referrerArray['arguments'])) {
205 $serializedArgumentsWithHmac = $referrerArray['arguments'];
206 $serializedArguments = $this->hashService->validateAndStripHmac($serializedArgumentsWithHmac);
207 $arguments = unserialize(base64_decode($serializedArguments));
208 unset($referrerArray['arguments']);
209 }
210 $referringRequest->setArguments(\TYPO3\CMS\Extbase\Utility\ArrayUtility::arrayMergeRecursiveOverrule($arguments, $referrerArray));
211 return $referringRequest;
212 }
213 return NULL;
214 }
215 }
216
217 ?>