* added common extension files
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Web / TX_EXTMVC_Web_RequestBuilder.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 * Builds a web request object from the raw HTTP information
26 *
27 * @version $Id:$
28 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
29 */
30 class RequestBuilder {
31
32 /**
33 * @var F3_FLOW3_Object_FactoryInterface $objectFactory: A reference to the Object Factory
34 */
35 protected $objectFactory;
36
37 /**
38 * @var F3_FLOW3_Utility_Environment
39 */
40 protected $environment;
41
42 /**
43 * @var F3_FLOW3_Configuration_Manager
44 */
45 protected $configurationManager;
46
47 /**
48 * @var TX_EXTMVC_Web_RouterInterface
49 */
50 protected $router;
51
52 /**
53 * Constructs this Web Request Builder
54 *
55 * @param F3_FLOW3_Object_FactoryInterface $objectFactory A reference to the object factory
56 * @author Robert Lemke <robert@typo3.org>
57 */
58 public function __construct(F3_FLOW3_Object_FactoryInterface $objectFactory) {
59 $this->objectFactory = $objectFactory;
60 }
61
62 /**
63 * Injects the server environment
64 *
65 * @param F3_FLOW3_Utility_Environment $environment The environment
66 * @return void
67 * @author Robert Lemke <robert@typo3.org>
68 */
69 public function injectEnvironment(F3_FLOW3_Utility_Environment $environment) {
70 $this->environment = $environment;
71 }
72
73 /**
74 * Injects the configuration manager
75 *
76 * @param F3_FLOW3_Configuration_Manager $configurationManager A reference to the configuration manager
77 * @return void
78 * @author Robert Lemke <robert@typo3.org>
79 */
80 public function injectConfigurationManager(F3_FLOW3_Configuration_Manager $configurationManager) {
81 $this->configurationManager = $configurationManager;
82 }
83
84 /**
85 * Injects a router for routing the web request
86 *
87 * @param TX_EXTMVC_Web_Routing_RouterInterface $router A router which routes the web request to a controller and action
88 * @return void
89 * @author Robert Lemke <robert@typo3.org>
90 */
91 public function injectRouter(TX_EXTMVC_Web_Routing_RouterInterface $router) {
92 $this->router = $router;
93 }
94
95 /**
96 * Builds a web request object from the raw HTTP information
97 *
98 * @return TX_EXTMVC_Web_Request The web request as an object
99 * @author Robert Lemke <robert@typo3.org>
100 */
101 public function build() {
102 $request = $this->objectFactory->create('F3_FLOW3_MVC_Web_Request');
103 $request->injectEnvironment($this->environment);
104 $request->setRequestURI($this->environment->getRequestURI());
105 $request->setMethod($this->environment->getRequestMethod());
106
107 $routesConfiguration = $this->configurationManager->getSpecialConfiguration(F3_FLOW3_Configuration_Manager::CONFIGURATION_TYPE_ROUTES);
108 $this->router->setRoutesConfiguration($routesConfiguration);
109 $this->router->route($request);
110
111 return $request;
112 }
113 }
114 ?>