da8506dc93148c010cd3608f6386ea715d56ba02
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / MVC / Web / RequestBuilder.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Builds a web request.
27 *
28 * @package TYPO3
29 * @subpackage extbase
30 * @version $ID:$
31 *
32 * @scope prototype
33 */
34 class Tx_ExtBase_MVC_Web_RequestBuilder {
35
36 /**
37 * Builds a web request object from the raw HTTP information
38 *
39 * @return \F3\FLOW3\MVC\Web\Request The web request as an object
40 * @author Robert Lemke <robert@typo3.org>
41 */
42 public function build($configuration) {
43 $pluginKey = $configuration['pluginKey'];
44 $extensionName = ($configuration['extensionName'] !== NULL) ? $configuration['extensionName'] : 'ExtBase';
45 $controllerConfigurations = is_array($configuration['controllers.']) ? $configuration['controllers.'] : array();
46 $defaultControllerConfiguration = current($controllerConfigurations);
47 $defaultControllerName = ($defaultControllerConfiguration['controllerName'] !== NULL) ? $defaultControllerConfiguration['controllerName'] : 'Default';
48 $defaultControllerActions = t3lib_div::trimExplode(',', $defaultControllerConfiguration['actions']);
49 $defaultActionName = (!empty($defaultControllerActions[0])) ? $defaultControllerActions[0] : 'index';
50 $allowedControllerActions = array();
51 foreach ($controllerConfigurations as $controllerConfiguration) {
52 $controllerActions = t3lib_div::trimExplode(',', $controllerConfiguration['actions']);
53 foreach ($controllerActions as $actionName) {
54 $allowedControllerActions[$controllerConfiguration['controllerName']][] = $actionName;
55 }
56 }
57 $parameters = t3lib_div::_GET('tx_' . strtolower($extensionName) . '_' . strtolower($pluginKey)); // TODO Parameters are unvalidated!
58 if (is_string($parameters['controller']) && array_key_exists($parameters['controller'], $allowedControllerActions)) {
59 $controllerName = stripslashes($parameters['controller']);
60 } elseif ($defaultControllerConfiguration['controllerName'] !== NULL) {
61 $controllerName = $defaultControllerName;
62 }
63
64 $allowedActions = $allowedControllerActions[$controllerName];
65 if (is_string($parameters['action']) && is_array($allowedActions) && in_array($parameters['action'], $allowedActions)) {
66 $actionName = filter_var($parameters['action'], FILTER_SANITIZE_STRING);
67 } elseif (is_string($defaultControllerConfiguration['actions'])) {;
68 $actions = t3lib_div::trimExplode(',', $defaultControllerConfiguration['actions']);
69 $actionName = $actions[0];
70 }
71
72 $request = t3lib_div::makeInstance('Tx_ExtBase_MVC_Web_Request');
73 $request->setPluginKey($pluginKey);
74 $request->setExtensionName($extensionName);
75 $request->setControllerName($controllerName);
76 $request->setControllerActionName($actionName);
77 $request->setRequestURI(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'));
78 $request->setBaseURI(t3lib_div::getIndpEnv('TYPO3_SITE_URL'));
79 foreach (t3lib_div::GParrayMerged('tx_' . strtolower($extensionName) . '_' . strtolower($pluginKey)) as $key => $value) {
80 $request->setArgument($key, $value);
81 }
82 return $request;
83 }
84
85
86 }
87 ?>