* added property aggregateRootClassName and the getters and setters
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Web / TX_EXTMVC_Web_Request.php
1 <?php
2 declare(ENCODING = 'utf-8');
3
4 /* *
5 * This script belongs to the FLOW3 framework. *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License as published by the *
9 * Free Software Foundation, either version 3 of the License, or (at your *
10 * option) any later version. *
11 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
22 * */
23
24 /**
25 * Represents a web request.
26 *
27 * @version $Id:$
28 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
29 *
30 * @scope prototype
31 */
32 class TX_EXTMVC_Web_Request extends TX_EXTMVC_Request {
33
34 /**
35 * @var string The requested representation format
36 */
37 protected $format = 'html';
38
39 /**
40 * @var string Contains the request method
41 */
42 protected $method = 'GET';
43
44 /**
45 * @var F3_FLOW3_Utility_Environment
46 */
47 protected $environment;
48
49 /**
50 * @var F3_FLOW3_Property_DataType_URI The request URI
51 */
52 protected $requestURI;
53
54 /**
55 * @var F3_FLOW3_Property_DataType_URI The base URI for this request - ie. the host and path leading to the index.php
56 */
57 protected $baseURI;
58
59 /**
60 * Sets the request method
61 *
62 * @param string $method Name of the request method
63 * @return void
64 * @author Robert Lemke <robert@typo3.org>
65 * @throws TX_EXTMVC_Exception_InvalidRequestMethod if the request method is not supported
66 */
67 public function setMethod($method) {
68 if ($method === '' || (strtoupper($method) !== $method)) throw new TX_EXTMVC_Exception_InvalidRequestMethod('The request method "' . $method . '" is not supported.', 1217778382);
69 $this->method = $method;
70 }
71
72 /**
73 * Returns the name of the request method
74 *
75 * @return string Name of the request method - one of the F3_FLOW3_Utility_Environment::REQUEST_METHOD_* constants
76 * @author Robert Lemke <robert@typo3.org>
77 */
78 public function getMethod() {
79 return $this->method;
80 }
81
82 /**
83 * Sets the request URI
84 *
85 * @param F3_FLOW3_Property_DataType_URI $requestURI URI of this web request
86 * @return void
87 * @author Robert Lemke <robert@typo3.org>
88 */
89 public function setRequestURI(F3_FLOW3_Property_DataType_URI $requestURI) {
90 $this->requestURI = clone $requestURI;
91 $this->baseURI = $this->detectBaseURI($requestURI);
92 }
93
94 /**
95 * Returns the request URI
96 *
97 * @return F3_FLOW3_Property_DataType_URI URI of this web request
98 * @author Robert Lemke <robert@typo3.org>
99 */
100 public function getRequestURI() {
101 return $this->requestURI;
102 }
103
104 /**
105 * Sets the base URI for this request.
106 *
107 * @param F3_FLOW3_Property_DataType_URI $baseURI New base URI
108 * @return void
109 * @author Robert Lemke <robert@typo3.org>
110 */
111 public function setBaseURI(F3_FLOW3_Property_DataType_URI $baseURI) {
112 $this->baseURI = clone $baseURI;
113 }
114
115 /**
116 * Returns the base URI
117 *
118 * @return F3_FLOW3_Property_DataType_URI Base URI of this web request
119 * @author Robert Lemke <robert@typo3.org>
120 */
121 public function getBaseURI() {
122 return $this->baseURI;
123 }
124
125 /**
126 * Tries to detect the base URI of this request and returns it.
127 *
128 * @param F3_FLOW3_Property_DataType_URI $requestURI URI of this web request
129 * @return F3_FLOW3_Property_DataType_URI The detected base URI
130 * @author Robert Lemke <robert@typo3.org>
131 */
132 protected function detectBaseURI(F3_FLOW3_Property_DataType_URI $requestURI) {
133 $baseURI = clone $requestURI;
134 $baseURI->setQuery(NULL);
135 $baseURI->setFragment(NULL);
136
137 $requestPathSegments = explode('/', $this->environment->getScriptRequestPathAndName());
138 array_pop($requestPathSegments);
139 $baseURI->setPath(implode('/', $requestPathSegments) . '/');
140 return $baseURI;
141 }
142 }
143 ?>