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
{
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;
78 public function initialize($configuration) {
79 if (!empty($configuration['pluginName'])) {
80 $this->pluginName
= $configuration['pluginName'];
82 if (!empty($configuration['extensionName'])) {
83 $this->extensionName
= $configuration['extensionName'];
85 if (!empty($configuration['controller'])) {
86 $this->defaultControllerName
= $configuration['controller'];
87 } elseif (is_array($configuration['switchableControllerActions'])) {
88 $firstControllerActions = current($configuration['switchableControllerActions']);
89 $this->defaultControllerName
= $firstControllerActions['controller'];
91 if (!empty($configuration['action'])) {
92 $this->defaultActionName
= $configuration['action'];
93 } elseif (is_array($configuration['switchableControllerActions'])) {
94 $firstControllerActions = current($configuration['switchableControllerActions']);
95 $this->defaultActionName
= array_shift(t3lib_div
::trimExplode(',', $firstControllerActions['actions'], TRUE));
97 $allowedControllerActions = array();
98 if (is_array($configuration['switchableControllerActions'])) {
99 foreach ($configuration['switchableControllerActions'] as $controller => $controllerConfiguration) {
100 $controllerActions = t3lib_div
::trimExplode(',', $controllerConfiguration['actions'], TRUE);
101 foreach ($controllerActions as $actionName) {
102 $allowedControllerActions[$controller][] = $actionName;
106 $this->allowedControllerActions
= $allowedControllerActions;
110 * Injects the object manager
112 * @param Tx_Extbase_Object_ObjectManagerInterface $objectManager
115 public function injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface
$objectManager) {
116 $this->objectManager
= $objectManager;
120 * Builds a web request object from the raw HTTP information and the configuration
122 * @return Tx_Extbase_MVC_Web_Request The web request as an object
124 public function build() {
125 $pluginSignature = strtolower($this->extensionName
. '_' . $this->pluginName
);
126 $pluginNamespace = Tx_Extbase_Utility_Extension
::getPluginNamespaceByPluginSignature($pluginSignature);
127 $parameters = t3lib_div
::_GPmerged($pluginNamespace);
129 if (is_string($parameters['controller']) && array_key_exists($parameters['controller'], $this->allowedControllerActions
)) {
130 $controllerName = filter_var($parameters['controller'], FILTER_SANITIZE_STRING
);
131 $allowedActions = $this->allowedControllerActions
[$controllerName];
132 if (is_string($parameters['action']) && is_array($allowedActions) && in_array($parameters['action'], $allowedActions)) {
133 $actionName = filter_var($parameters['action'], FILTER_SANITIZE_STRING
);
135 $actionName = $this->defaultActionName
;
138 $controllerName = $this->defaultControllerName
;
139 $actionName = $this->defaultActionName
;
142 $request = $this->objectManager
->create('Tx_Extbase_MVC_Web_Request');
143 $request->setPluginName($this->pluginName
);
144 $request->setControllerExtensionName($this->extensionName
);
145 $request->setControllerName($controllerName);
146 $request->setControllerActionName($actionName);
147 $request->setRequestURI(t3lib_div
::getIndpEnv('TYPO3_REQUEST_URL'));
148 $request->setBaseURI(t3lib_div
::getIndpEnv('TYPO3_SITE_URL'));
149 $request->setMethod((isset($_SERVER['REQUEST_METHOD'])) ?
$_SERVER['REQUEST_METHOD'] : NULL);
151 if (is_string($parameters['format']) && (strlen($parameters['format']))) {
152 $request->setFormat(filter_var($parameters['format'], FILTER_SANITIZE_STRING
));
155 foreach ($parameters as $argumentName => $argumentValue) {
156 $request->setArgument($argumentName, $argumentValue);