Extbase:
authorJochen Rau <j.rau@web.de>
Fri, 15 May 2009 14:50:39 +0000 (14:50 +0000)
committerJochen Rau <j.rau@web.de>
Fri, 15 May 2009 14:50:39 +0000 (14:50 +0000)
* Moved class.tx_extbase_dispatcher.php to Classes/Dispatcher.php

typo3/sysext/extbase/Classes/Dispatcher.php [new file with mode: 0644]
typo3/sysext/extbase/Classes/MVC/Web/RequestBuilder.php
typo3/sysext/extbase/Classes/Persistence/Mapper/DataMap.php
typo3/sysext/extbase/Tests/Base_testcase.php
typo3/sysext/extbase/Tests/MVC/Web/RequestBuilder_testcase.php
typo3/sysext/extbase/class.tx_extbase_dispatcher.php [deleted file]
typo3/sysext/extbase/ext_localconf.php

diff --git a/typo3/sysext/extbase/Classes/Dispatcher.php b/typo3/sysext/extbase/Classes/Dispatcher.php
new file mode 100644 (file)
index 0000000..4d685c6
--- /dev/null
@@ -0,0 +1,153 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+require_once(t3lib_extMgm::extPath('extbase') . 'Classes/Utility/Strings.php');
+
+/**
+ * Creates a request an dispatches it to the controller which was specified
+ * by TS Setup, Flexform and returns the content to the v4 framework.
+ *
+ * @package TYPO3
+ * @subpackage extbase
+ * @version $ID:$
+ */
+class Tx_Extbase_Dispatcher {
+
+       /**
+        * Creates a request an dispatches it to a controller.
+        *
+        * @param string $content The content
+        * @param array|NULL $configuration The TS configuration array
+        * @return string $content The processed content
+        */
+       public function dispatch($content, $configuration) {
+               if (!is_array($configuration)) {
+                       t3lib_div::sysLog('Extbase was not able to dispatch the request. No configuration.', 'extbase', t3lib_div::SYSLOG_SEVERITY_ERROR);
+                       return $content;
+               }
+               $requestBuilder = t3lib_div::makeInstance('Tx_Extbase_MVC_Web_RequestBuilder');
+               $request = $requestBuilder->initialize($configuration);
+               $request = $requestBuilder->build();
+               $response = t3lib_div::makeInstance('Tx_Extbase_MVC_Web_Response');
+               $persistenceSession = t3lib_div::makeInstance('Tx_Extbase_Persistence_Session'); // singleton
+
+               $dispatchLoopCount = 0;
+               while (!$request->isDispatched()) {
+                       if ($dispatchLoopCount++ > 99) throw new TxExtbase_MVC_Exception_InfiniteLoop('Could not ultimately dispatch the request after '  . $dispatchLoopCount . ' iterations.', 1217839467);
+                       $controller = $this->getPreparedController($request);
+                       try {
+                               $controller->processRequest($request, $response);
+                       } catch (Tx_Extbase_Exception_StopAction $ignoredException) {
+                       } catch (Tx_Extbase_Exception_InvalidArgumentValue $exception) {
+                               $persistenceSession->clear();
+                               return '';
+                       }
+               }
+
+               // var_dump($persistenceSession);
+               $persistenceSession->commit();
+               $persistenceSession->clear();
+               if (count($response->getAdditionalHeaderData()) > 0) {
+                       $GLOBALS['TSFE']->additionalHeaderData[$request->getControllerExtensionName()] = implode("\n", $response->getAdditionalHeaderData());
+               }
+               // TODO Handle $response->getStatus()
+               $response->sendHeaders();
+               return $response->getContent();
+       }
+
+       /**
+        * Builds and returns a controller
+        *
+        * @param Tx_Extbase_MVC_Web_Request $request
+        * @return Tx_Extbase_MVC_Controller_ControllerInterface The prepared controller
+        */
+       protected function getPreparedController(Tx_Extbase_MVC_Web_Request $request) {
+               $controllerObjectName = $request->getControllerObjectName();
+               $controller = t3lib_div::makeInstance($controllerObjectName);
+               if (!$controller instanceof Tx_Extbase_MVC_Controller_ControllerInterface) {
+                       throw new Tx_Extbase_Exception_InvalidController('Invalid controller "' . $request->getControllerObjectName() . '". The controller must implement the Tx_Extbase_MVC_Controller_ControllerInterface.', 1202921619);
+               }
+               $propertyMapper = t3lib_div::makeInstance('Tx_Extbase_Property_Mapper');
+               $controller->injectPropertyMapper($propertyMapper);
+               $controller->injectSettings($this->getSettings($request));
+               $URIHelper = t3lib_div::makeInstance('Tx_Extbase_MVC_View_Helper_URIHelper');
+               $URIHelper->setRequest($request);
+               $controller->injectURIHelper($URIHelper);
+               $reflectionService = t3lib_div::makeInstance('Tx_Extbase_Reflection_Service');
+               $validatorResolver = t3lib_div::makeInstance('Tx_Extbase_Validation_ValidatorResolver');
+               $validatorResolver->injectReflectionService($reflectionService);
+               $controller->injectValidatorResolver($validatorResolver);
+               $controller->injectReflectionService($reflectionService);
+               return $controller;
+       }
+
+       /**
+        * Builds the settings by overlaying TS Setup with FlexForm values of the extension
+        * and returns them as a plain array (with no trailing dots).
+        *
+        * @param Tx_Extbase_MVC_Web_Request $request
+        * @return array The settings array
+        */
+       protected function getSettings(Tx_Extbase_MVC_Web_Request $request) {
+               $extensionName = $request->getControllerExtensionName();
+               $configurationSources = array();
+               $configurationSources[] = t3lib_div::makeInstance('Tx_Extbase_Configuration_Source_TypoScriptSource');
+               if (!empty($this->cObj->data['pi_flexform'])) {
+                       $configurationSource = t3lib_div::makeInstance('Tx_Extbase_Configuration_Source_FlexFormSource');
+                       $configurationSource->setFlexFormContent($this->cObj->data['pi_flexform']);
+                       $configurationSources[] = $configurationSource;
+               }
+               $configurationManager = t3lib_div::makeInstance('Tx_Extbase_Configuration_Manager', $configurationSources);
+               return $configurationManager->getSettings($extensionName);
+       }
+
+       /**
+        * Loads php files containing classes or interfaces found in the classes directory of
+        * an extension.
+        *
+        * @param string $className: Name of the class/interface to load
+        * @uses t3lib_extMgm::extPath()
+        * @return void
+        */
+       public static function autoloadClass($className) {
+               $classNameParts = explode('_', $className);
+               $extensionKey = Tx_Extbase_Utility_Strings::camelCaseToLowerCaseUnderscored($classNameParts[1]);
+               if (t3lib_extMgm::isLoaded($extensionKey)) {
+                       if ($classNameParts[0] === 'ux') {
+                               array_shift($classNameParts);
+                       }
+                       $className = implode('_', $classNameParts);
+                       if (count($classNameParts) > 2 && $classNameParts[0] === 'Tx') {
+                               $classFilePathAndName = t3lib_extMgm::extPath(Tx_Extbase_Utility_Strings::camelCaseToLowerCaseUnderscored($classNameParts[1])) . 'Classes/';
+                               $classFilePathAndName .= implode(array_slice($classNameParts, 2, -1), '/') . '/';
+                               $classFilePathAndName .= array_pop($classNameParts) . '.php';
+                       }
+                       if (isset($classFilePathAndName) && file_exists($classFilePathAndName)) {
+                               require_once($classFilePathAndName);
+                       }
+               }
+       }
+
+}
+?>
\ No newline at end of file
index 52185c6..790b545 100755 (executable)
@@ -129,14 +129,13 @@ class Tx_Extbase_MVC_Web_RequestBuilder {
                $request->setMethod((isset($_SERVER['REQUEST_METHOD'])) ? $_SERVER['REQUEST_METHOD'] : NULL);
                $GET = t3lib_div::_GET('tx_' . strtolower($this->extensionName) . '_' . strtolower($this->pluginName));
                if (is_array($GET)) {
-                       foreach ($GET as $key => $value) {
-                               $request->setArgument($key, $value);
+                       foreach ($GET as $argumentName => $argumentValue) {
+                               $request->setArgument($argumentName, $argumentValue);
                        }
                }
                if ($request->getMethod() === 'POST') {
-                       $POST = $_POST;
-                       if (is_array($POST)) {
-                               foreach ($POST as $argumentName => $argumentValue) {
+                       if (is_array($_POST)) {
+                               foreach ($_POST as $argumentName => $argumentValue) {
                                        $request->setArgument($argumentName, $argumentValue);
                                }
                        }
index 6487f06..9c4fe63 100644 (file)
@@ -56,6 +56,7 @@ class Tx_Extbase_Persistence_Mapper_DataMap {
         *
         * @param string $className The class name. This determines the table to fetch the configuration for
         */
+       // TODO Refactor to factory pattern (DataMapFactory) and value object (DataMap)  
        public function __construct($className) {
                $this->setClassName($className);
                $this->setTableName($this->determineTableName($className));
@@ -141,6 +142,7 @@ class Tx_Extbase_Persistence_Mapper_DataMap {
         * @return void
         */
        protected function addCommonColumns() {
+               // TODO Decide whether we should add pid and uid columns by default
                $this->addColumn('uid', Tx_Extbase_Persistence_Mapper_ColumnMap::TYPE_INTEGER);
                $this->addColumn('pid', Tx_Extbase_Persistence_Mapper_ColumnMap::TYPE_INTEGER);
                if ($this->hasTimestampColumn()) {
index e281047..7bf2e7a 100644 (file)
@@ -22,7 +22,7 @@
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
 
-require_once(t3lib_extMgm::extPath('extbase', 'class.tx_extbase_dispatcher.php'));
+require_once(t3lib_extMgm::extPath('extbase', 'Classes/Dispatcher.php'));
 
 /**
  * Base testcase for the Extbase extension. Currently it only registers the autoloader.
index 4afca83..7fa540e 100644 (file)
@@ -30,7 +30,7 @@ class Tx_Extbase_MVC_Web_RequestBuilder_testcase extends Tx_Extbase_Base_testcas
        
        public function setUp() {
                $this->configuration = array(
-                       'userFunc' => 'tx_extbase_dispatcher->dispatch',
+                       'userFunc' => 'Tx_Extbase_Dispatcher->dispatch',
                        'pluginName' => 'pi1',
                        'extensionName' => 'MyExtension',
                        'controller' => 'TheFirstController',
diff --git a/typo3/sysext/extbase/class.tx_extbase_dispatcher.php b/typo3/sysext/extbase/class.tx_extbase_dispatcher.php
deleted file mode 100644 (file)
index 64110e2..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-<?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-*  All rights reserved
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
-
-require_once(t3lib_extMgm::extPath('extbase') . 'Classes/Utility/Strings.php');
-
-/**
- * Creates a request an dispatches it to the controller which was specified
- * by TS Setup, Flexform and returns the content to the v4 framework.
- *
- * @package TYPO3
- * @subpackage extbase
- * @version $ID:$
- */
-class Tx_Extbase_Dispatcher {
-
-       /**
-        * Creates a request an dispatches it to a controller.
-        *
-        * @param string $content The content
-        * @param array|NULL $configuration The TS configuration array
-        * @return string $content The processed content
-        */
-       public function dispatch($content, $configuration) {
-               if (!is_array($configuration)) {
-                       t3lib_div::sysLog('Extbase was not able to dispatch the request. No configuration.', 'extbase', t3lib_div::SYSLOG_SEVERITY_ERROR);
-                       return $content;
-               }
-               $requestBuilder = t3lib_div::makeInstance('Tx_Extbase_MVC_Web_RequestBuilder');
-               $request = $requestBuilder->initialize($configuration);
-               $request = $requestBuilder->build();
-               $response = t3lib_div::makeInstance('Tx_Extbase_MVC_Web_Response');
-               $persistenceSession = t3lib_div::makeInstance('Tx_Extbase_Persistence_Session');
-
-               $dispatchLoopCount = 0;
-               while (!$request->isDispatched()) {
-                       if ($dispatchLoopCount++ > 99) throw new TxExtbase_MVC_Exception_InfiniteLoop('Could not ultimately dispatch the request after '  . $dispatchLoopCount . ' iterations.', 1217839467);
-                       $controller = $this->getPreparedController($request);
-                       try {
-                               $controller->processRequest($request, $response);
-                       } catch (Tx_Extbase_Exception_StopAction $ignoredException) {
-                       } catch (Tx_Extbase_Exception_InvalidArgumentValue $exception) {
-                               $persistenceSession->clear();
-                               return '';
-                       }
-               }
-
-               // var_dump($persistenceSession);
-               $persistenceSession->commit();
-               $persistenceSession->clear();
-               if (count($response->getAdditionalHeaderData()) > 0) {
-                       $GLOBALS['TSFE']->additionalHeaderData[$request->getControllerExtensionName()] = implode("\n", $response->getAdditionalHeaderData());
-               }
-               // TODO Handle $response->getStatus()
-               $response->sendHeaders();
-               return $response->getContent();
-       }
-
-       /**
-        * Builds and returns a controller
-        *
-        * @param Tx_Extbase_MVC_Web_Request $request
-        * @return Tx_Extbase_MVC_Controller_ControllerInterface The prepared controller
-        */
-       protected function getPreparedController(Tx_Extbase_MVC_Web_Request $request) {
-               $controllerObjectName = $request->getControllerObjectName();
-               $controller = t3lib_div::makeInstance($controllerObjectName);
-               if (!$controller instanceof Tx_Extbase_MVC_Controller_ControllerInterface) {
-                       throw new Tx_Extbase_Exception_InvalidController('Invalid controller "' . $request->getControllerObjectName() . '". The controller must implement the Tx_Extbase_MVC_Controller_ControllerInterface.', 1202921619);
-               }
-               $propertyMapper = t3lib_div::makeInstance('Tx_Extbase_Property_Mapper');
-               $controller->injectPropertyMapper($propertyMapper);
-               $controller->injectSettings($this->getSettings($request));
-               $URIHelper = t3lib_div::makeInstance('Tx_Extbase_MVC_View_Helper_URIHelper');
-               $URIHelper->setRequest($request);
-               $controller->injectURIHelper($URIHelper);
-               $reflectionService = t3lib_div::makeInstance('Tx_Extbase_Reflection_Service');
-               $validatorResolver = t3lib_div::makeInstance('Tx_Extbase_Validation_ValidatorResolver');
-               $validatorResolver->injectReflectionService($reflectionService);
-               $controller->injectValidatorResolver($validatorResolver);
-               $controller->injectReflectionService($reflectionService);
-               return $controller;
-       }
-
-       /**
-        * Builds the settings by overlaying TS Setup with FlexForm values of the extension
-        * and returns them as a plain array (with no trailing dots).
-        *
-        * @param Tx_Extbase_MVC_Web_Request $request
-        * @return array The settings array
-        */
-       protected function getSettings(Tx_Extbase_MVC_Web_Request $request) {
-               $extensionName = $request->getControllerExtensionName();
-               $configurationSources = array();
-               $configurationSources[] = t3lib_div::makeInstance('Tx_Extbase_Configuration_Source_TypoScriptSource');
-               if (!empty($this->cObj->data['pi_flexform'])) {
-                       $configurationSource = t3lib_div::makeInstance('Tx_Extbase_Configuration_Source_FlexFormSource');
-                       $configurationSource->setFlexFormContent($this->cObj->data['pi_flexform']);
-                       $configurationSources[] = $configurationSource;
-               }
-               $configurationManager = t3lib_div::makeInstance('Tx_Extbase_Configuration_Manager', $configurationSources);
-               return $configurationManager->getSettings($extensionName);
-       }
-
-       /**
-        * Loads php files containing classes or interfaces found in the classes directory of
-        * an extension.
-        *
-        * @param string $className: Name of the class/interface to load
-        * @uses t3lib_extMgm::extPath()
-        * @return void
-        */
-       public static function autoloadClass($className) {
-               $classNameParts = explode('_', $className);
-               $extensionKey = Tx_Extbase_Utility_Strings::camelCaseToLowerCaseUnderscored($classNameParts[1]);
-               if (t3lib_extMgm::isLoaded($extensionKey)) {
-                       if ($classNameParts[0] === 'ux') {
-                               array_shift($classNameParts);
-                       }
-                       $className = implode('_', $classNameParts);
-                       if (count($classNameParts) > 2 && $classNameParts[0] === 'Tx') {
-                               $classFilePathAndName = t3lib_extMgm::extPath(Tx_Extbase_Utility_Strings::camelCaseToLowerCaseUnderscored($classNameParts[1])) . 'Classes/';
-                               $classFilePathAndName .= implode(array_slice($classNameParts, 2, -1), '/') . '/';
-                               $classFilePathAndName .= array_pop($classNameParts) . '.php';
-                       }
-                       if (isset($classFilePathAndName) && file_exists($classFilePathAndName)) {
-                               require_once($classFilePathAndName);
-                       }
-               }
-       }
-
-}
-?>
\ No newline at end of file
index 5c2adca..b6dc1ca 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 if (!defined ('TYPO3_MODE'))   die ('Access denied.');
 
-require_once(t3lib_extMgm::extPath('extbase') . 'class.tx_extbase_dispatcher.php');
+require_once(t3lib_extMgm::extPath('extbase') . 'Classes/Dispatcher.php');
 spl_autoload_register(array('Tx_Extbase_Dispatcher', 'autoloadClass'));
 
 # $GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'EXT:extbase/Classes/Persistence/Hook/TCEMainValueObjectUpdater.php:tx_Extbase_Persistence_Hook_TCEMainValueObjectUpdater';