58be3503796ed48e306861efd768cc9bc155e9ac
[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 $controllerActions = t3lib_div::trimExplode(',', $defaultControllerConfiguration['actions']);
49 $defaultActionName = (!empty($controllerActions[0])) ? $controllerActions[0] : 'index';
50 $allowedControllerActions = array();
51 foreach ($controllerConfigurations as $controller) {
52 foreach ($controllerActions as $actionName) {
53 $allowedControllerActions[$controller['controllerName']][] = $actionName;
54 }
55 }
56 $parameters = t3lib_div::_GET('tx_' . strtolower($extensionName) . '_' . strtolower($pluginKey)); // TODO Parameters are unvalidated!
57 if (is_string($parameters['controller']) && array_key_exists($parameters['controller'], $allowedControllerActions)) {
58 $controllerName = stripslashes($parameters['controller']);
59 } elseif ($defaultControllerConfiguration['controllerName'] !== NULL) {
60 $controllerName = $defaultControllerName;
61 }
62
63 $allowedActions = $allowedControllerActions[$controllerName];
64 if (is_string($parameters['action']) && is_array($allowedActions) && in_array($parameters['action'], $allowedActions)) {
65 $actionName = filter_var($parameters['action'], FILTER_SANITIZE_STRING);
66 } elseif (is_string($defaultControllerConfiguration['actions'])) {;
67 $actions = t3lib_div::trimExplode(',', $defaultControllerConfiguration['actions']);
68 $actionName = $actions[0];
69 }
70
71 $request = t3lib_div::makeInstance('Tx_ExtBase_MVC_Web_Request');
72 $request->setPluginKey($pluginKey);
73 $request->setExtensionName($extensionName);
74 $request->setControllerName($controllerName);
75 $request->setControllerActionName($actionName);
76 $request->setRequestURI(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'));
77 $request->setBaseURI(t3lib_div::getIndpEnv('TYPO3_SITE_URL'));
78 foreach (t3lib_div::GParrayMerged('tx_' . strtolower($extensionName) . '_' . strtolower($pluginKey)) as $key => $value) {
79 $request->setArgument($key, $value);
80 }
81 return $request;
82 }
83
84
85 }
86 ?>