2 /***************************************************************
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
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.
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
29 * Builds a web request.
37 class Tx_Extbase_MVC_Web_RequestBuilder
{
40 * This is a unique key for a plugin (not the extension key!)
44 protected $pluginName = 'plugin';
47 * The name of the extension (in UpperCamelCase)
51 protected $extensionName = 'Extbase';
54 * The default controller name
58 protected $defaultControllerName = 'Standard';
61 * The default action of the default controller
65 protected $defaultActionName = 'index';
68 * The allowed actions of the controller. This actions can be called via $_GET and $_POST.
72 protected $allowedControllerActions;
74 public function initialize($configuration) {
75 if (!empty($configuration['pluginName'])) {
76 $this->pluginName
= $configuration['pluginName'];
78 if (!empty($configuration['extensionName'])) {
79 $this->extensionName
= $configuration['extensionName'];
81 if (!empty($configuration['controller'])) {
82 $this->defaultControllerName
= $configuration['controller'];
83 } elseif (is_array($configuration['switchableControllerActions.'])) {
84 $firstControllerActions = current($configuration['switchableControllerActions.']);
85 $this->defaultControllerName
= $firstControllerActions['controller'];
87 if (!empty($configuration['action'])) {
88 $this->defaultActionName
= $configuration['action'];
89 } elseif (is_array($configuration['switchableControllerActions.'])) {
90 $firstControllerActions = current($configuration['switchableControllerActions.']);
91 $this->defaultActionName
= array_shift(t3lib_div
::trimExplode(',', $firstControllerActions['actions'], TRUE));
93 $allowedControllerActions = array();
94 if (is_array($configuration['switchableControllerActions.'])) {
95 foreach ($configuration['switchableControllerActions.'] as $controllerConfiguration) {
96 $controllerActions = t3lib_div
::trimExplode(',', $controllerConfiguration['actions']);
97 foreach ($controllerActions as $actionName) {
98 $allowedControllerActions[$controllerConfiguration['controller']][] = $actionName;
102 $this->allowedControllerActions
= $allowedControllerActions;
106 * Builds a web request object from the raw HTTP information and the configuration
108 * @return Tx_Extbase_MVC_Web_Request The web request as an object
110 public function build() {
111 $parameters = t3lib_div
::_GPmerged('tx_' . strtolower($this->extensionName
) . '_' . strtolower($this->pluginName
));
113 if (is_string($parameters['controller']) && array_key_exists($parameters['controller'], $this->allowedControllerActions
)) {
114 $controllerName = filter_var($parameters['controller'], FILTER_SANITIZE_STRING
);
115 $allowedActions = $this->allowedControllerActions
[$controllerName];
116 if (is_string($parameters['action']) && is_array($allowedActions) && in_array($parameters['action'], $allowedActions)) {
117 $actionName = filter_var($parameters['action'], FILTER_SANITIZE_STRING
);
119 $actionName = $this->defaultActionName
;
122 $controllerName = $this->defaultControllerName
;
123 $actionName = $this->defaultActionName
;
126 $request = t3lib_div
::makeInstance('Tx_Extbase_MVC_Web_Request');
127 $request->setPluginName($this->pluginName
);
128 $request->setControllerExtensionName($this->extensionName
);
129 $request->setControllerName($controllerName);
130 $request->setControllerActionName($actionName);
131 $request->setRequestURI(t3lib_div
::getIndpEnv('TYPO3_REQUEST_URL'));
132 $request->setBaseURI(t3lib_div
::getIndpEnv('TYPO3_SITE_URL'));
133 $request->setMethod((isset($_SERVER['REQUEST_METHOD'])) ?
$_SERVER['REQUEST_METHOD'] : NULL);
135 foreach ($parameters as $argumentName => $argumentValue) {
136 $request->setArgument($argumentName, $argumentValue);