|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de> 00006 * All rights reserved 00007 * 00008 * This class is a backport of the corresponding class of FLOW3. 00009 * All credits go to the v5 team. 00010 * 00011 * This script is part of the TYPO3 project. The TYPO3 project is 00012 * free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License as published by 00014 * the Free Software Foundation; either version 2 of the License, or 00015 * (at your option) any later version. 00016 * 00017 * The GNU General Public License can be found at 00018 * http://www.gnu.org/copyleft/gpl.html. 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 00028 /** 00029 * Builds a web request. 00030 * 00031 * @package Extbase 00032 * @subpackage MVC\Web 00033 * @version $ID:$ 00034 * 00035 * @scope prototype 00036 */ 00037 class Tx_Extbase_MVC_Web_RequestBuilder implements t3lib_Singleton { 00038 00039 /** 00040 * @var Tx_Extbase_Object_ObjectManagerInterface 00041 */ 00042 protected $objectManager; 00043 00044 /** 00045 * This is a unique key for a plugin (not the extension key!) 00046 * 00047 * @var string 00048 */ 00049 protected $pluginName = 'plugin'; 00050 00051 /** 00052 * The name of the extension (in UpperCamelCase) 00053 * 00054 * @var string 00055 */ 00056 protected $extensionName; 00057 00058 /** 00059 * The default controller name 00060 * 00061 * @var string 00062 */ 00063 protected $defaultControllerName; 00064 00065 /** 00066 * The default action of the default controller 00067 * 00068 * @var string 00069 */ 00070 protected $defaultActionName; 00071 00072 /** 00073 * The allowed actions of the controller. This actions can be called via $_GET and $_POST. 00074 * 00075 * @var array 00076 */ 00077 protected $allowedControllerActions = array(); 00078 00079 /** 00080 * @var Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager 00081 */ 00082 protected $configurationManager; 00083 00084 /** 00085 * @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager 00086 */ 00087 public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) { 00088 $this->configurationManager = $configurationManager; 00089 } 00090 00091 /** 00092 * Injects the object manager 00093 * 00094 * @param Tx_Extbase_Object_ObjectManagerInterface $objectManager 00095 * @return void 00096 */ 00097 public function injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface $objectManager) { 00098 $this->objectManager = $objectManager; 00099 } 00100 00101 /** 00102 * @return void 00103 */ 00104 protected function loadDefaultValues() { 00105 $configuration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); 00106 if (empty($configuration['extensionName'])) { 00107 throw new Tx_Extbase_MVC_Exception('"extensionName" is not properly configured. Request can\'t be dispatched!', 1289843275); 00108 } 00109 if (empty($configuration['pluginName'])) { 00110 throw new Tx_Extbase_MVC_Exception('"pluginName" is not properly configured. Request can\'t be dispatched!', 1289843277); 00111 } 00112 $this->extensionName = $configuration['extensionName']; 00113 $this->pluginName = $configuration['pluginName']; 00114 00115 $frameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); 00116 $controllerConfiguration = $frameworkConfiguration['controllerConfiguration']; 00117 $this->defaultControllerName = current(array_keys($controllerConfiguration)); 00118 $this->defaultActionName = current($controllerConfiguration[$this->defaultControllerName]['actions']); 00119 00120 $allowedControllerActions = array(); 00121 foreach ($controllerConfiguration as $controllerName => $controllerActions) { 00122 $allowedControllerActions[$controllerName] = $controllerActions['actions']; 00123 } 00124 $this->allowedControllerActions = $allowedControllerActions; 00125 } 00126 00127 /** 00128 * Builds a web request object from the raw HTTP information and the configuration 00129 * 00130 * @return Tx_Extbase_MVC_Web_Request The web request as an object 00131 */ 00132 public function build() { 00133 $this->loadDefaultValues(); 00134 $pluginNamespace = Tx_Extbase_Utility_Extension::getPluginNamespace($this->extensionName, $this->pluginName); 00135 $parameters = t3lib_div::_GPmerged($pluginNamespace); 00136 00137 if (is_string($parameters['controller']) && array_key_exists($parameters['controller'], $this->allowedControllerActions)) { 00138 $controllerName = filter_var($parameters['controller'], FILTER_SANITIZE_STRING); 00139 } elseif (!empty($this->defaultControllerName)) { 00140 $controllerName = $this->defaultControllerName; 00141 } else { 00142 throw new Tx_Extbase_MVC_Exception( 00143 'The default controller can not be determined.<br />' 00144 . 'Please check for Tx_Extbase_Utility_Extension::configurePlugin() in your ext_localconf.php.', 00145 1295479650 00146 ); 00147 } 00148 00149 $allowedActions = $this->allowedControllerActions[$controllerName]; 00150 if (is_string($parameters['action']) && is_array($allowedActions) && in_array($parameters['action'], $allowedActions)) { 00151 $actionName = filter_var($parameters['action'], FILTER_SANITIZE_STRING); 00152 } elseif (!empty($this->defaultActionName)) { 00153 $actionName = $this->defaultActionName; 00154 } else { 00155 throw new Tx_Extbase_MVC_Exception( 00156 'The default action can not be determined for controller "' . $controllerName . '".<br />' 00157 . 'Please check Tx_Extbase_Utility_Extension::configurePlugin() in your ext_localconf.php.', 00158 1295479651 00159 ); 00160 } 00161 00162 $request = $this->objectManager->create('Tx_Extbase_MVC_Web_Request'); 00163 $request->setPluginName($this->pluginName); 00164 $request->setControllerExtensionName($this->extensionName); 00165 $request->setControllerName($controllerName); 00166 $request->setControllerActionName($actionName); 00167 $request->setRequestURI(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL')); 00168 $request->setBaseURI(t3lib_div::getIndpEnv('TYPO3_SITE_URL')); 00169 $request->setMethod((isset($_SERVER['REQUEST_METHOD'])) ? $_SERVER['REQUEST_METHOD'] : NULL); 00170 00171 if (is_string($parameters['format']) && (strlen($parameters['format']))) { 00172 $request->setFormat(filter_var($parameters['format'], FILTER_SANITIZE_STRING)); 00173 } 00174 00175 foreach ($parameters as $argumentName => $argumentValue) { 00176 $request->setArgument($argumentName, $argumentValue); 00177 } 00178 00179 return $request; 00180 } 00181 00182 00183 } 00184 ?>
1.8.0