EXTMVC:
authorJochen Rau <j.rau@web.de>
Tue, 17 Mar 2009 11:43:44 +0000 (11:43 +0000)
committerJochen Rau <j.rau@web.de>
Tue, 17 Mar 2009 11:43:44 +0000 (11:43 +0000)
* Added FlexForm and TypoScript configuration source

typo3/sysext/extbase/Classes/Configuration/Source/TX_EXTMVC_Configuration_Source_FlexForm.php [new file with mode: 0644]
typo3/sysext/extbase/Classes/Configuration/Source/TX_EXTMVC_Configuration_Source_PHP.php
typo3/sysext/extbase/Classes/Configuration/Source/TX_EXTMVC_Configuration_Source_TS.php
typo3/sysext/extbase/Classes/Configuration/Source/TX_EXTMVC_Configuration_Source_YAML.php [deleted file]
typo3/sysext/extbase/Classes/Configuration/TX_EXTMVC_Configuration_Container.php
typo3/sysext/extbase/Classes/Configuration/TX_EXTMVC_Configuration_Manager.php
typo3/sysext/extbase/Classes/Configuration/TX_EXTMVC_Configuration_SourceInterface.php
typo3/sysext/extbase/Classes/Persistence/Mapper/TX_EXTMVC_Persistence_Mapper_ObjectRelationalMapper.php
typo3/sysext/extbase/Classes/View/TX_EXTMVC_View_TemplateView.php
typo3/sysext/extbase/class.tx_extmvc_dispatcher.php

diff --git a/typo3/sysext/extbase/Classes/Configuration/Source/TX_EXTMVC_Configuration_Source_FlexForm.php b/typo3/sysext/extbase/Classes/Configuration/Source/TX_EXTMVC_Configuration_Source_FlexForm.php
new file mode 100644 (file)
index 0000000..45feef8
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+
+/*                                                                        *
+ * This script is part of the TYPO3 project - inspiring people to share!  *
+ *                                                                        *
+ * TYPO3 is free software; you can redistribute it and/or modify it under *
+ * the terms of the GNU General Public License version 2 as published by  *
+ * the Free Software Foundation.                                          *
+ *                                                                        *
+ * This script is distributed in the hope that it will be useful, but     *
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
+ * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
+ * Public License for more details.                                       *
+ *                                                                        */
+
+/**
+ * Configuration source based on FlexForm settings
+ *
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
+ */
+class TX_EXTMVC_Configuration_Source_FlexForm implements TX_EXTMVC_Configuration_SourceInterface {
+
+       /**
+        * XML FlexForm content
+        *
+        * @var string
+        **/
+       protected $flexFormContent;
+
+       public function setFlexFormContent($flexFormContent) {
+               $this->flexFormContent = $flexFormContent;
+       }
+
+       /**
+        * Loads the specified TypoScript configuration file and returns its content in a
+        * configuration container. If the file does not exist or could not be loaded,
+        * the empty configuration container is returned.
+        *
+        * @param string $extensionKey The extension key
+        * @return TX_EXTMVC_Configuration_Container
+        */
+        public function load($extensionKey) {
+               $settings = array();
+               if (!is_array($this->flexFormContent) && $this->flexFormContent) {
+                       $flexFormArray = t3lib_div::xml2array($this->flexFormContent);
+               }
+               $sheetArray = $flexFormArray['data']['sDEF']['lDEF'];
+               if (is_array($sheetArray))      {
+                       foreach($sheetArray as $key => $value) {
+                               $settings[$key] = $value['vDEF'];
+                       }
+               }
+               return $settings;
+       }
+
+}
+?>
\ No newline at end of file
index f19bf97..84296e8 100644 (file)
@@ -33,11 +33,12 @@ class TX_EXTMVC_Configuration_Source_PHP implements TX_EXTMVC_Configuration_Sour
         * array. If the file does not exist or could not be loaded, an empty
         * array is returned
         *
-        * @param string $pathAndFilename Full path and file name of the file to load, excluding the file extension (ie. ".php")
+        * @param string $extensionKey The extension key
         * @return array
         */
-       public function load($pathAndFilename) {
-               $c = new TX_EXTMVC_Configuration_Container();
+       public function load($extensionKey) {
+               $pathAndFilename = t3lib_extMgm::extPath(strtolower($extensionKey)) . '/Configuration/Settings');
+               $c = t3lib_div::makeInstance('TX_EXTMVC_Configuration_Container');
                if (file_exists($pathAndFilename . '.php')) {
                        require ($pathAndFilename . '.php');
                }
index 1f5972d..302f877 100644 (file)
@@ -25,16 +25,16 @@ class TX_EXTMVC_Configuration_Source_TS implements TX_EXTMVC_Configuration_Sourc
         * configuration container. If the file does not exist or could not be loaded,
         * the empty configuration container is returned.
         *
-        * @param string $pathAndFilename Full path and file name of the file to load
+        * @param string $extensionKey The extension key
         * @return TX_EXTMVC_Configuration_Container
         */
-        public static function load($pathAndFilename) {
-               $typoScript = t3lib_div::getURL($pathAndFilename);
-               $parser = new t3lib_tsparser();
-               $parser->parse($typoScript);
-               $settings = $parser->setup['plugin.']['TX_' . $extensionKey . '.'][$configurationType . '.'];
-               $c = new F3_GimmeFive_Configuration_Container();
-               $c->mergeWithTS($settings);
+        public function load($extensionKey) {
+               $settings = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_' . strtolower($extensionKey) . '.'];
+               $c = t3lib_div::makeInstance('TX_EXTMVC_Configuration_Container');
+               if (is_array($settings)) {
+                       $c = t3lib_div::makeInstance('TX_EXTMVC_Configuration_Container');
+                       $c->mergeWithTS($settings);
+               }
                return $c->getAsArray();
        }
 
diff --git a/typo3/sysext/extbase/Classes/Configuration/Source/TX_EXTMVC_Configuration_Source_YAML.php b/typo3/sysext/extbase/Classes/Configuration/Source/TX_EXTMVC_Configuration_Source_YAML.php
deleted file mode 100644 (file)
index 08ddef9..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-
-/*                                                                        *
- * This script belongs to the FLOW3 framework.                            *
- *                                                                        *
- * It is free software; you can redistribute it and/or modify it under    *
- * the terms of the GNU Lesser General Public License as published by the *
- * Free Software Foundation, either version 3 of the License, or (at your *
- * option) any later version.                                             *
- *                                                                        *
- * This script is distributed in the hope that it will be useful, but     *
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
- * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
- * General Public License for more details.                               *
- *                                                                        *
- * You should have received a copy of the GNU Lesser General Public       *
- * License along with the script.                                         *
- * If not, see http://www.gnu.org/licenses/lgpl.html                      *
- *                                                                        *
- * The TYPO3 project - inspiring people to share!                         *
- *                                                                        */
-
-/**
- * Configuration source based on YAML files
- *
- * @version $Id:$
- * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
- */
-class TX_EXTMVC_Configuration_Source_YAML implements TX_EXTMVC_Configuration_SourceInterface {
-
-       /**
-        * Loads the specified configuration file and returns its content as an
-        * array. If the file does not exist or could not be loaded, an empty
-        * array is returned
-        *
-        * @param string $pathAndFilename Full path and file name of the file to load, excluding the file extension (ie. ".yaml")
-        * @return array
-        */
-       public function load($pathAndFilename) {
-               if (file_exists($pathAndFilename . '.yaml')) {
-                       try {
-                               $configuration = F3_YAML_YAML::loadFile($pathAndFilename . '.yaml');
-                       } catch (TX_EXTMVC_Error_Exception $exception) {
-                               throw new TX_EXTMVC_Configuration_Exception_ParseError('A parse error occurred while parsing file "' . $pathAndFilename . '.yaml". Error message: ' . $exception->getMessage(), 1232014321);
-                       }
-               } else {
-                       $configuration = array();
-               }
-               return $configuration;
-       }
-}
-?>
\ No newline at end of file
index 085616a..040f990 100644 (file)
@@ -26,7 +26,7 @@
  * @version $Id:$
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class Container implements Countable, Iterator, ArrayAccess {
+class TX_EXTMVC_Configuration_Container implements Countable, Iterator, ArrayAccess {
 
        /**
         * @var array Configuration options and their values
index b198491..965087e 100644 (file)
@@ -38,7 +38,7 @@ class TX_EXTMVC_Configuration_Manager implements t3lib_Singleton {
        protected $settings = array();
 
        /**
-        * The configuration sources used for loading the raw configuration
+        * The configuration source instances used for loading the raw configuration
         *
         * @var array
         */
@@ -47,7 +47,7 @@ class TX_EXTMVC_Configuration_Manager implements t3lib_Singleton {
        /**
         * Constructs the configuration manager
         *
-        * @param array $configurationSources An array of configuration sources
+        * @param array $configurationSourcesObjectNames An array of object names of the configuration sources
         */
        public function __construct(array $configurationSources) {
                $this->configurationSources = $configurationSources;
@@ -59,11 +59,34 @@ class TX_EXTMVC_Configuration_Manager implements t3lib_Singleton {
         * @param string $extensionKey Key of the extension to return the settings for
         * @return array The settings of the specified extension
         */
-       public function getSettings($extensionKey) {
-               if (isset($this->settings[$extensionKey])) {
+       public function getSettings($extensionKey, $controllerName = '', $actionName = '') {
+               $settings = array();
+               if (is_array($this->settings[$extensionKey])) {
                        $settings = $this->settings[$extensionKey];
-               } else {
-                       $settings = array();
+                       if (!empty($controllerName) && is_array($settings[$controllerName])) {
+                               if (!empty($actionName) && is_array($settings[$controllerName][$actionName])) {
+                                       $settings = $settings[$controllerName][$actionName];
+                               } else {
+                                       $settings = $settings[$controllerName];
+                               }
+                       }
+                       // if (!empty($controllerName) && is_array($settings[$controllerName])) {
+                       //      foreach ($settings[$controllerName] as $key => $value) {
+                       //              if (array_key_exists($key, $settings)) {
+                       //                      $settings[$key] = $value;
+                       //              }
+                       //      }
+                       // }
+                       // if (!empty($actionName) && is_array($settings[$controllerName][$actionName])) {
+                       //      foreach ($settings[$controllerName][$actionName] as $key => $value) {
+                       //              if (array_key_exists($key, $settings)) {
+                       //                      $settings[$key] = $value;
+                       //              }
+                       //              if (array_key_exists($key, $settings[$controllerName])) {
+                       //                      $settings[$controllerName][$key] = $value;
+                       //              }
+                       //      }
+                       // }
                }
                return $settings;
        }
@@ -80,37 +103,14 @@ class TX_EXTMVC_Configuration_Manager implements t3lib_Singleton {
         * @see getSettings()
         */
        public function loadGlobalSettings($extensionKey) {
+               $settings = $this->settings[$extensionKey];
+               if (empty($settings)) $settings = array();
                foreach ($this->configurationSources as $configurationSource) {
-                       $settings = t3lib_div::arrayMergeRecursiveOverrule($settings, $configurationSource->load(FLOW3_PATH_PACKAGES . $extensionKey . '/Configuration/Settings'));
+                       $settings = t3lib_div::array_merge_recursive_overrule($settings, $configurationSource->load($extensionKey));
                }
-               $this->postProcessSettings($settings);
-               $this->settings = t3lib_div::arrayMergeRecursiveOverrule($this->settings, $settings);
+               // $this->postProcessSettings($settings);
+               $this->settings[$extensionKey] = $settings;
        }
 
-       /**
-        * Post processes the given settings array by replacing constants with their
-        * actual value.
-        *
-        * This is a preliminary solution, we'll surely have some better way to handle
-        * this soon.
-        *
-        * @param array &$settings The settings to post process. The results are stored directly in the given array
-        * @return void
-        */
-       protected function postProcessSettings(&$settings) {
-               foreach ($settings as $key => $setting) {
-                       if (is_array($setting)) {
-                               $this->postProcessSettings($settings[$key]);
-                       } elseif (is_string($setting)) {
-                               $matches = array();
-                               preg_match_all('/(?:%)([a-zA-Z_0-9]+)(?:%)/', $setting, $matches);
-                               if (count($matches[1]) > 0) {
-                                       foreach ($matches[1] as $match) {
-                                               if (defined($match)) $settings[$key] = str_replace('%' . $match . '%', constant($match), $settings[$key]);
-                                       }
-                               }
-                       }
-               }
-       }
 }
 ?>
\ No newline at end of file
index 5512849..7a7fcda 100644 (file)
@@ -32,10 +32,9 @@ interface TX_EXTMVC_Configuration_SourceInterface {
         * Loads the specified configuration file and returns its content in a
         * configuration container
         *
-        * @param string $pathAndFilename Full path and file name of the file to load, excluding the dot and file extension
+        * @param string $extensionKey The extension key
         * @return TX_EXTMVC_Configuration_Container
-        * @throws TX_EXTMVC_Configuration_Exception_NoSuchFile if the specified file does not exist
         */
-       public function load($pathAndFilename);
+       public function load($extensionKey);
 }
 ?>
\ No newline at end of file
index 790283b..e9a6eaa 100644 (file)
@@ -114,7 +114,7 @@ class TX_EXTMVC_Persistence_Mapper_ObjectRelationalMapper implements t3lib_Singl
                $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
                        $columnMap->getChildTableName() . '.*, ' . $columnMap->getRelationTableName() . '.*',
                        $columnMap->getChildTableName() . ' LEFT JOIN ' . $columnMap->getRelationTableName() . ' ON (' . $columnMap->getChildTableName() . '.uid=' . $columnMap->getRelationTableName() . '.uid_foreign)',
-                       $where . ' AND ' . $columnMap->getRelationTableName() . '.uid_local=' . intval($parentObject->getUid()) . $this->cObj->enableFields($columnMap->getChildTableName()) . $this->cObj->enableFields($columnMap->getChildTableName()),
+                       $where . ' AND ' . $columnMap->getRelationTableName() . '.uid_local=' . t3lib_div::intval_positive($parentObject->getUid()) . $this->cObj->enableFields($columnMap->getChildTableName()) . $this->cObj->enableFields($columnMap->getChildTableName()),
                        $groupBy,
                        $orderBy,
                        $limit
index 6dd679d..00c6e7e 100644 (file)
@@ -173,7 +173,6 @@ class TX_EXTMVC_View_TemplateView extends TX_EXTMVC_View_AbstractView {
         */
        public function render() {
                if ($this->templateSource == '') {
-                       $this->actionName = $action;
                        $templateFileName = $this->resolveTemplateFile();
                        $templateSource = $this->loadTemplateFile($templateFileName);
                } else {
index 1794c8b..7f29fce 100644 (file)
@@ -26,6 +26,7 @@ require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/TX_EXTMVC_Request.php');
 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Web/TX_EXTMVC_Web_Request.php');
 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/TX_EXTMVC_Response.php');
 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Web/TX_EXTMVC_Web_Response.php');
+require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Configuration/TX_EXTMVC_Configuration_Manager.php');
 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Controller/TX_EXTMVC_Controller_AbstractController.php');
 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Controller/TX_EXTMVC_Controller_ActionController.php');
 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Controller/TX_EXTMVC_Controller_Arguments.php');
@@ -82,26 +83,33 @@ class TX_EXTMVC_Dispatcher {
         *
         * @param String $content The content
         * @param array|NULL $configuration The TS configuration array
+        * @uses t3lib_div::_GET()
+        * @uses t3lib_div::makeInstance()
+        * @uses t3lib_div::GParrayMerged()
+        * @uses t3lib_div::getIndpEnv()
         * @return String $content The processed content
         */
        public function dispatch($content, $configuration) {
+
+               $start_time = microtime(TRUE);
+
                $parameters = t3lib_div::_GET('tx_extmvc');
-               // TODO Is stripslashes secure enough?
                $extensionKey = isset($parameters['extension']) ? stripslashes($parameters['extension']) : $configuration['extension'];
-               $controller = isset($parameters['controller']) ? stripslashes($parameters['controller']) : $configuration['controller'];
-               $action = isset($parameters['action']) ? stripslashes($parameters['action']) : $configuration['action'];
+               $controllerName = isset($parameters['controller']) ? stripslashes($parameters['controller']) : $configuration['controller'];
+               $actionName = isset($parameters['action']) ? stripslashes($parameters['action']) : $configuration['action'];
                
                $request = t3lib_div::makeInstance('TX_EXTMVC_Web_Request');
                $request->setControllerExtensionKey($extensionKey);
-               $request->setControllerName($controller);
-               $request->setControllerActionName($action);
+               $request->setControllerName($controllerName);
+               $request->setControllerActionName($actionName);
 
                $controllerObjectName = $request->getControllerObjectName();
                $controller = t3lib_div::makeInstance($controllerObjectName);
                
                if (!$controller instanceof TX_EXTMVC_Controller_AbstractController) throw new TX_EXTMVC_Exception_InvalidController('Invalid controller "' . $controllerObjectName . '". The controller must be a valid request handling controller.', 1202921619);
 
-               if (!$controller->isCachableAction($action) && $this->cObj->getUserObjectType() === tslib_cObj::OBJECTTYPE_USER) {                      
+               if (!$controller->isCachableAction($actionName) && $this->cObj->getUserObjectType() === tslib_cObj::OBJECTTYPE_USER) {
+                       // FIXME Caching does nort work because it's by default a USER object, so the dispatcher is never called
                        $this->cObj->convertToUserIntObject();
                        return $content;
                }
@@ -116,8 +124,18 @@ class TX_EXTMVC_Dispatcher {
                $request->setRequestURI(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'));
                $request->setBaseURI(t3lib_div::getIndpEnv('TYPO3_SITE_URL'));
                $response = t3lib_div::makeInstance('TX_EXTMVC_Web_Response');
-
-               $settings = is_array($configuration['settings.']) ? $configuration['settings.'] : array();
+               
+               $configurationSources = array();
+               $configurationSources[] = t3lib_div::makeInstance('TX_EXTMVC_Configuration_Source_TS');
+               if (!empty($this->cObj->data['pi_flexform'])) {
+                       $configurationSource = t3lib_div::makeInstance('TX_EXTMVC_Configuration_Source_FlexForm');
+                       $configurationSource->setFlexFormContent($this->cObj->data['pi_flexform']);
+                       $configurationSources[] = $configurationSource;
+               }
+               $configurationManager = t3lib_div::makeInstance('TX_EXTMVC_Configuration_Manager', $configurationSources);
+               $configurationManager->loadGlobalSettings($extensionKey);
+               $configurationManager = t3lib_div::makeInstance('TX_EXTMVC_Configuration_Manager');
+               $settings = $configurationManager->getSettings($extensionKey);
                $controller->injectSettings($settings);
 
                $session = t3lib_div::makeInstance('TX_EXTMVC_Persistence_Session');
@@ -130,6 +148,9 @@ class TX_EXTMVC_Dispatcher {
                
                $GLOBALS['TSFE']->additionalHeaderData[$request->getControllerExtensionKey()] = implode("\n", $response->getAdditionalHeaderTags());
                
+               $end_time = microtime(TRUE);
+               debug($end_time - $start_time, -1);
+
                return $response->getContent();
        }
 
@@ -138,6 +159,7 @@ class TX_EXTMVC_Dispatcher {
         * an extension.
         *
         * @param string $className: Name of the class/interface to load
+        * @uses t3lib_extMgm::extPath()
         * @return void
         */
        protected function autoLoadClasses($className) {