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
implements t3lib_Singleton
{
39 * @var Tx_Extbase_Object_ObjectManagerInterface
41 protected $objectManager;
44 * This is a unique key for a plugin (not the extension key!)
48 protected $pluginName = 'plugin';
51 * The name of the extension (in UpperCamelCase)
55 protected $extensionName = 'Extbase';
58 * The default controller name
62 protected $defaultControllerName = 'Standard';
65 * The default action of the default controller
69 protected $defaultActionName = 'index';
72 * The allowed actions of the controller. This actions can be called via $_GET and $_POST.
76 protected $allowedControllerActions;
79 * @var Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager
81 protected $configurationManager;
84 * @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager
86 public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface
$configurationManager) {
87 $this->configurationManager
= $configurationManager;
91 * Injects the object manager
93 * @param Tx_Extbase_Object_ObjectManagerInterface $objectManager
96 public function injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface
$objectManager) {
97 $this->objectManager
= $objectManager;
103 protected function loadDefaultValues() {
104 $configuration = $this->configurationManager
->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface
::CONFIGURATION_TYPE_FRAMEWORK
);
105 if (!empty($configuration['pluginName'])) {
106 $this->pluginName
= $configuration['pluginName'];
108 if (!empty($configuration['extensionName'])) {
109 $this->extensionName
= $configuration['extensionName'];
111 if (!empty($configuration['controller'])) {
112 $this->defaultControllerName
= $configuration['controller'];
113 } elseif (is_array($configuration['switchableControllerActions'])) {
114 $firstControllerActions = current($configuration['switchableControllerActions']);
115 $this->defaultControllerName
= $firstControllerActions['controller'];
117 if (!empty($configuration['action'])) {
118 $this->defaultActionName
= $configuration['action'];
119 } elseif (is_array($configuration['switchableControllerActions'])) {
120 $firstControllerActions = current($configuration['switchableControllerActions']);
121 $this->defaultActionName
= array_shift(t3lib_div
::trimExplode(',', $firstControllerActions['actions'], TRUE));
123 $allowedControllerActions = array();
124 if (is_array($configuration['switchableControllerActions'])) {
125 foreach ($configuration['switchableControllerActions'] as $controller => $controllerConfiguration) {
126 $controllerActions = t3lib_div
::trimExplode(',', $controllerConfiguration['actions'], TRUE);
127 foreach ($controllerActions as $actionName) {
128 $allowedControllerActions[$controller][] = $actionName;
132 $this->allowedControllerActions
= $allowedControllerActions;
136 * Builds a web request object from the raw HTTP information and the configuration
138 * @return Tx_Extbase_MVC_Web_Request The web request as an object
140 public function build() {
141 $this->loadDefaultValues();
142 $pluginNamespace = Tx_Extbase_Utility_Extension
::getPluginNamespace($this->extensionName
, $this->pluginName
);
143 $parameters = t3lib_div
::_GPmerged($pluginNamespace);
145 if (is_string($parameters['controller']) && array_key_exists($parameters['controller'], $this->allowedControllerActions
)) {
146 $controllerName = filter_var($parameters['controller'], FILTER_SANITIZE_STRING
);
147 $allowedActions = $this->allowedControllerActions
[$controllerName];
148 if (is_string($parameters['action']) && is_array($allowedActions) && in_array($parameters['action'], $allowedActions)) {
149 $actionName = filter_var($parameters['action'], FILTER_SANITIZE_STRING
);
151 $actionName = $this->defaultActionName
;
154 $controllerName = $this->defaultControllerName
;
155 $actionName = $this->defaultActionName
;
158 $request = $this->objectManager
->create('Tx_Extbase_MVC_Web_Request');
159 $request->setPluginName($this->pluginName
);
160 $request->setControllerExtensionName($this->extensionName
);
161 $request->setControllerName($controllerName);
162 $request->setControllerActionName($actionName);
163 $request->setRequestURI(t3lib_div
::getIndpEnv('TYPO3_REQUEST_URL'));
164 $request->setBaseURI(t3lib_div
::getIndpEnv('TYPO3_SITE_URL'));
165 $request->setMethod((isset($_SERVER['REQUEST_METHOD'])) ?
$_SERVER['REQUEST_METHOD'] : NULL);
167 if (is_string($parameters['format']) && (strlen($parameters['format']))) {
168 $request->setFormat(filter_var($parameters['format'], FILTER_SANITIZE_STRING
));
171 foreach ($parameters as $argumentName => $argumentValue) {
172 $request->setArgument($argumentName, $argumentValue);