EXTMVC:
authorJochen Rau <j.rau@web.de>
Mon, 16 Mar 2009 21:51:24 +0000 (21:51 +0000)
committerJochen Rau <j.rau@web.de>
Mon, 16 Mar 2009 21:51:24 +0000 (21:51 +0000)
* Adapted TemplateView to meet the changes in the Templates folder structure
* First step towards the implementation of the ConfigurationManager

12 files changed:
typo3/sysext/extbase/Classes/Configuration/Source/TX_EXTMVC_Configuration_Source_PHP.php
typo3/sysext/extbase/Classes/Configuration/Source/TX_EXTMVC_Configuration_Source_TS.php [new file with mode: 0644]
typo3/sysext/extbase/Classes/Configuration/Source/TX_EXTMVC_Configuration_Source_YAML.php
typo3/sysext/extbase/Classes/Configuration/TX_EXTMVC_Configuration_Container.php
typo3/sysext/extbase/Classes/Configuration/TX_EXTMVC_Configuration_Exception.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/TX_EXTMVC_Persistence_RepositoryInterface.php
typo3/sysext/extbase/Classes/Validation/Validator/TX_EXTMVC_Validation_Validator_ChainValidator.php
typo3/sysext/extbase/Classes/View/TX_EXTMVC_View_TemplateView.php
typo3/sysext/extbase/Tests/Fixtures/TX_EXTMVC_Tests_Fixtures_Entity.php
typo3/sysext/extbase/class.tx_extmvc_dispatcher.php

index b54e476..f19bf97 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 PHP implements TX_EXTMVC_Configuration_SourceInterface {
+class TX_EXTMVC_Configuration_Source_PHP implements TX_EXTMVC_Configuration_SourceInterface {
 
        /**
         * Loads the specified configuration file and returns its content as an
diff --git a/typo3/sysext/extbase/Classes/Configuration/Source/TX_EXTMVC_Configuration_Source_TS.php b/typo3/sysext/extbase/Classes/Configuration/Source/TX_EXTMVC_Configuration_Source_TS.php
new file mode 100644 (file)
index 0000000..1f5972d
--- /dev/null
@@ -0,0 +1,42 @@
+<?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 TS settings
+ *
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
+ */
+class TX_EXTMVC_Configuration_Source_TS implements TX_EXTMVC_Configuration_SourceInterface {
+
+       /**
+        * 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 $pathAndFilename Full path and file name of the file to load
+        * @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);
+               return $c->getAsArray();
+       }
+
+}
+?>
\ No newline at end of file
index 1a6b3a0..08ddef9 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 YAML implements TX_EXTMVC_Configuration_SourceInterface {
+class TX_EXTMVC_Configuration_Source_YAML implements TX_EXTMVC_Configuration_SourceInterface {
 
        /**
         * Loads the specified configuration file and returns its content as an
@@ -40,7 +40,7 @@ class YAML implements TX_EXTMVC_Configuration_SourceInterface {
                if (file_exists($pathAndFilename . '.yaml')) {
                        try {
                                $configuration = F3_YAML_YAML::loadFile($pathAndFilename . '.yaml');
-                       } catch (F3_FLOW3_Error_Exception $exception) {
+                       } 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 {
index c953ea4..085616a 100644 (file)
@@ -88,6 +88,25 @@ class Container implements Countable, Iterator, ArrayAccess {
                }
                return $optionsArray;
        }
+       
+       /**
+        * Returns the this container as a TypoScript array (with the dot "." as a suffix for keys)
+        *
+        * @param mixed $options A plain value or a F3_FLOW3_Configuration_Container 
+        * @return array This container converted to a TypoScript array
+        */
+       public function getAsTsArray() {
+               $optionsArray = array();
+               foreach ($this->options as $key => $value) {
+                       if ($value instanceof F3_GimmeFive_Configuration_Container) {
+                               $key = $key . '.';
+                               $optionsArray[$key] = $this->getAsTsArray();
+                       } else {
+                               $optionsArray[$key] = $value;
+                       }
+               }
+               return $optionsArray;
+       }
 
        /**
         * Locks this configuration container agains write access.
@@ -130,7 +149,27 @@ class Container implements Countable, Iterator, ArrayAccess {
                }
                return $this;
        }
-
+       
+       /**
+        * Merges this container with an array already build from TS
+        *
+        * @param array $setup The array
+        * @return TX_EXTMVC_Configuration_Container This container
+        */
+       public function mergeWithTS(array $settings) {
+               foreach ($settings as $optionName => $newOptionValue) {
+                       $optionName = preg_match('/(.*)\.{0,1}$/Uu', $optionName, $matches); // remove postfixed dot
+                       $optionName = $matches[1];
+                       if (is_array($newOptionValue)) {
+                               $existingOptionValue = $this->__get($optionName);
+                               if (!($existingOptionValue instanceof TX_EXTMVC_Configuration_Container)) $existingOptionValue = new TX_EXTMVC_Configuration_Container();
+                               $newOptionValue = $existingOptionValue->mergeWithTS($newOptionValue);
+                       }
+                       $this->__set($optionName, $newOptionValue);
+               }
+               return $this;
+       }
+       
        /**
         * Returns the number of configuration options
         *
index 156ca57..c4681ac 100644 (file)
@@ -30,7 +30,7 @@
  * @version $Id:$
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class Exception extends F3_FLOW3_Exception {
+class TX_EXTMVC_Configuration_Exception extends F3_FLOW3_Exception {
 
 }
 
index ce30bed..b198491 100644 (file)
@@ -20,9 +20,7 @@
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
-/**
- * @version $Id:$
- */
+require_once(PATH_t3lib . 'interfaces/interface.t3lib_singleton.php');
 
 /**
  * A general purpose configuration manager
  * @version $Id:$
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
  */
-class Manager {
-
-       const CONFIGURATION_TYPE_FLOW3 = 'FLOW3';
-       const CONFIGURATION_TYPE_PACKAGES = 'Packages';
-       const CONFIGURATION_TYPE_OBJECTS = 'Objects';
-       const CONFIGURATION_TYPE_SETTINGS = 'Settings';
-       const CONFIGURATION_TYPE_ROUTES = 'Routes';
-       const CONFIGURATION_TYPE_SIGNALSSLOTS = 'SignalsSlots';
-       const CONFIGURATION_TYPE_CACHES = 'Caches';
-
-       /**
-        * @var string The application context of the configuration to manage
-        */
-       protected $context;
+class TX_EXTMVC_Configuration_Manager implements t3lib_Singleton {
 
        /**
         * Storage for the settings, loaded by loadGlobalSettings()
@@ -52,17 +37,6 @@ class Manager {
         */
        protected $settings = array();
 
-       /**
-        * Storage of the raw special configurations
-        *
-        * @var array
-        */
-       protected $configurations = array(
-               'Routes' => array(),
-               'SignalsSlots' => array(),
-               'Caches' => array()
-       );
-
        /**
         * The configuration sources used for loading the raw configuration
         *
@@ -73,11 +47,9 @@ class Manager {
        /**
         * Constructs the configuration manager
         *
-        * @param string $context The application context to fetch configuration for.
         * @param array $configurationSources An array of configuration sources
         */
-       public function __construct($context, array $configurationSources) {
-               $this->context = $context;
+       public function __construct(array $configurationSources) {
                $this->configurationSources = $configurationSources;
        }
 
@@ -96,31 +68,6 @@ class Manager {
                return $settings;
        }
 
-       /**
-        * Loads the FLOW3 core settings defined in the FLOW3 extension and the global
-        * configuration directories.
-        *
-        * The FLOW3 settings can be retrieved like any other setting through the
-        * getSettings() method but need to be loaded separately because they are
-        * needed way earlier in the bootstrap than the extension's settings.
-        *
-        * @return void
-        * @internal
-        */
-       public function loadFLOW3Settings() {
-               $settings = array();
-               foreach ($this->configurationSources as $configurationSource) {
-                       $settings = F3_FLOW3_Utility_Arrays::arrayMergeRecursiveOverrule($settings, $configurationSource->load(FLOW3_PATH_PACKAGES . 'FLOW3/Configuration/FLOW3'));
-               }
-
-               foreach ($this->configurationSources as $configurationSource) {
-                       $settings = F3_FLOW3_Utility_Arrays::arrayMergeRecursiveOverrule($settings, $configurationSource->load(FLOW3_PATH_CONFIGURATION . 'FLOW3', TRUE));
-                       $settings = F3_FLOW3_Utility_Arrays::arrayMergeRecursiveOverrule($settings, $configurationSource->load(FLOW3_PATH_CONFIGURATION . $this->context . '/FLOW3', TRUE));
-               }
-               $this->postProcessSettings($settings);
-               $this->settings['FLOW3'] = $settings;
-       }
-
        /**
         * Loads the settings defined in the specified extensions and merges them with
         * those potentially existing in the global configuration folders.
@@ -128,109 +75,16 @@ class Manager {
         * The result is stored in the configuration manager's settings registry
         * and can be retrieved with the getSettings() method.
         *
-        * @param array $extensionKeys
+        * @param string $extensionKey
         * @return void
         * @see getSettings()
-        * @internal
         */
-       public function loadGlobalSettings(array $extensionKeys) {
-               $settings = array();
-               sort ($extensionKeys);
-               $index = array_search('FLOW3', $extensionKeys);
-               if ($index !== FALSE) {
-                       unset ($extensionKeys[$index]);
-                       array_unshift($extensionKeys, 'FLOW3');
-               }
-               foreach ($extensionKeys as $extensionKey) {
-                       foreach ($this->configurationSources as $configurationSource) {
-                               $settings = F3_FLOW3_Utility_Arrays::arrayMergeRecursiveOverrule($settings, $configurationSource->load(FLOW3_PATH_PACKAGES . $extensionKey . '/Configuration/Settings'));
-                       }
-               }
+       public function loadGlobalSettings($extensionKey) {
                foreach ($this->configurationSources as $configurationSource) {
-                       $settings = F3_FLOW3_Utility_Arrays::arrayMergeRecursiveOverrule($settings, $configurationSource->load(FLOW3_PATH_CONFIGURATION . 'Settings', TRUE));
-                       $settings = F3_FLOW3_Utility_Arrays::arrayMergeRecursiveOverrule($settings, $configurationSource->load(FLOW3_PATH_CONFIGURATION . $this->context . '/Settings', TRUE));
+                       $settings = t3lib_div::arrayMergeRecursiveOverrule($settings, $configurationSource->load(FLOW3_PATH_PACKAGES . $extensionKey . '/Configuration/Settings'));
                }
                $this->postProcessSettings($settings);
-               $this->settings = F3_FLOW3_Utility_Arrays::arrayMergeRecursiveOverrule($this->settings, $settings);
-       }
-
-       /**
-        * Loads special configuration defined in the specified extensions and merges them with
-        * those potentially existing in the global configuration folders.
-        *
-        * The result is stored in the configuration manager's configuration registry
-        * and can be retrieved with the getSpecialConfiguration() method. However note
-        * that this is only the raw information which will be further processed by other
-        * parts of FLOW3
-        *
-        * @param string $configurationType The kind of configuration to load - must be one of the CONFIGURATION_TYPE_* constants
-        * @param array $extensionKeys A list of extensions to consider
-        * @return void
-        * @internal
-        */
-       public function loadSpecialConfiguration($configurationType, array $extensionKeys) {
-               $index = array_search('FLOW3', $extensionKeys);
-               if ($index !== FALSE) {
-                       unset ($extensionKeys[$index]);
-                       array_unshift($extensionKeys, 'FLOW3');
-               }
-
-               foreach ($extensionKeys as $extensionKey) {
-                       foreach ($this->configurationSources as $configurationSource) {
-                               $this->configurations[$configurationType] = F3_FLOW3_Utility_Arrays::arrayMergeRecursiveOverrule($this->configurations[$configurationType], $configurationSource->load(FLOW3_PATH_PACKAGES . $extensionKey . '/Configuration/' . $configurationType));
-                       }
-               }
-               foreach ($this->configurationSources as $configurationSource) {
-                       $this->configurations[$configurationType] = F3_FLOW3_Utility_Arrays::arrayMergeRecursiveOverrule($this->configurations[$configurationType], $configurationSource->load(FLOW3_PATH_CONFIGURATION . $configurationType));
-               }
-               foreach ($this->configurationSources as $configurationSource) {
-                       $this->configurations[$configurationType] = F3_FLOW3_Utility_Arrays::arrayMergeRecursiveOverrule($this->configurations[$configurationType], $configurationSource->load(FLOW3_PATH_CONFIGURATION . $this->context . '/' . $configurationType));
-               }
-               $this->postProcessSettings($this->configurations[$configurationType]);
-       }
-
-       /**
-        * Loads and returns the specified raw configuration. The actual configuration will be
-        * merged from different sources in a defined order.
-        *
-        * Note that this is a very low level method and usually only makes sense to be used
-        * by FLOW3 internally.
-        *
-        * @param string $configurationType The kind of configuration to fetch - must be one of the CONFIGURATION_TYPE_* constants
-        * @param string $extensionKey Key of the extension the configuration is for
-        * @return array The configuration
-        * @throws TX_EXTMVC_Configuration_Exception_InvalidConfigurationType on invalid configuration types
-        * @internal
-        */
-       public function getSpecialConfiguration($configurationType, $extensionKey = 'FLOW3') {
-               switch ($configurationType) {
-                       case self::CONFIGURATION_TYPE_ROUTES :
-                       case self::CONFIGURATION_TYPE_SIGNALSSLOTS :
-                       case self::CONFIGURATION_TYPE_CACHES :
-                               return $this->configurations[$configurationType];
-                       case self::CONFIGURATION_TYPE_PACKAGES :
-                       case self::CONFIGURATION_TYPE_OBJECTS :
-                       break;
-                       default:
-                               throw new TX_EXTMVC_Configuration_Exception_InvalidConfigurationType('Invalid configuration type "' . $configurationType . '"', 1206031879);
-               }
-               $configuration = array();
-               foreach ($this->configurationSources as $configurationSource) {
-                       $configuration = F3_FLOW3_Utility_Arrays::arrayMergeRecursiveOverrule($configuration, $configurationSource->load(FLOW3_PATH_PACKAGES . $extensionKey . '/Configuration/' . $configurationType));
-               }
-               foreach ($this->configurationSources as $configurationSource) {
-                       $configuration = F3_FLOW3_Utility_Arrays::arrayMergeRecursiveOverrule($configuration, $configurationSource->load(FLOW3_PATH_CONFIGURATION . $configurationType));
-               }
-               foreach ($this->configurationSources as $configurationSource) {
-                       $configuration = F3_FLOW3_Utility_Arrays::arrayMergeRecursiveOverrule($configuration, $configurationSource->load(FLOW3_PATH_CONFIGURATION . $this->context . '/' . $configurationType));
-               }
-
-               switch ($configurationType) {
-                       case self::CONFIGURATION_TYPE_PACKAGES :
-                               return (isset($configuration[$extensionKey])) ? $configuration[$extensionKey] : array();
-                       case self::CONFIGURATION_TYPE_OBJECTS :
-                               return $configuration;
-               }
+               $this->settings = t3lib_div::arrayMergeRecursiveOverrule($this->settings, $settings);
        }
 
        /**
index 2538b18..5512849 100644 (file)
@@ -25,9 +25,8 @@
  *
  * @version $Id:$
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
- * @author Robert Lemke <robert@typo3.org>
  */
-interface SourceInterface {
+interface TX_EXTMVC_Configuration_SourceInterface {
 
        /**
         * Loads the specified configuration file and returns its content in a
index 9fc6e96..e60edf2 100644 (file)
@@ -25,7 +25,6 @@
  *
  * @version $Id:$
  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
- * @author Robert Lemke <robert@typo3.org>
  */
 interface TX_EXTMVC_Persistence_RepositoryInterface {
 
index 9ea6465..e4a4e1f 100644 (file)
@@ -60,7 +60,6 @@ class TX_EXTMVC_Validation_Validator_ChainValidator implements TX_EXTMVC_Validat
         *
         * @param TX_EXTMVC_Validation_Validator_ValidatorInterface $validator The validator that should be added
         * @return integer The index of the new chain entry
-        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function addValidator(TX_EXTMVC_Validation_Validator_ValidatorInterface $validator) {
                $this->validators[] = $validator;
@@ -73,7 +72,6 @@ class TX_EXTMVC_Validation_Validator_ChainValidator implements TX_EXTMVC_Validat
         * @param integer $index The index of the validator that should be returned
         * @return TX_EXTMVC_Validation_Validator_ValidatorInterface The requested validator
         * @throws TX_EXTMVC_Validation_Exception_InvalidChainIndex
-        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function getValidator($index) {
                if (!isset($this->validators[$index])) throw new TX_EXTMVC_Validation_Exception_InvalidChainIndex('Invalid chain index.', 1207215864);
@@ -84,7 +82,6 @@ class TX_EXTMVC_Validation_Validator_ChainValidator implements TX_EXTMVC_Validat
         * Removes the validator with the given index of the chain.
         *
         * @param integer $index The index of the validator that should be removed
-        * @author Andreas Förthner <andreas.foerthner@netlogix.de>
         */
        public function removeValidator($index) {
                if (!isset($this->validators[$index])) throw new TX_EXTMVC_Validation_Exception_InvalidChainIndex('Invalid chain index.', 1207020177);
index 03df05a..6dd679d 100644 (file)
@@ -51,7 +51,7 @@ class TX_EXTMVC_View_TemplateView extends TX_EXTMVC_View_AbstractView {
         * File pattern for resolving the template file
         * @var string
         */
-       protected $templateFilePattern = 'Resources/Template/@controller/@action.xhtml';
+       protected $templateFilePattern = 'Resources/Private/Templates/@controller/@action.html';
 
        /**
         * @var array Marker uids and their replacement content
index 151a828..0dc441d 100644 (file)
@@ -65,7 +65,6 @@ class TX_EXTMVC_Tests_Fixtures_Entity extends TX_EXTMVC_DomainObject_Entity {
        //  * Mock method
        //  *
        //  * @return void
-       //  * @author Jochen Rau <jochen.rau@typoplanet.de>
        //  */
        // public function _memorizeCleanState() {
        // }
index 2569a96..1794c8b 100644 (file)
@@ -85,7 +85,6 @@ class TX_EXTMVC_Dispatcher {
         * @return String $content The processed content
         */
        public function dispatch($content, $configuration) {
-               // $time_start = microtime(true);               
                $parameters = t3lib_div::_GET('tx_extmvc');
                // TODO Is stripslashes secure enough?
                $extensionKey = isset($parameters['extension']) ? stripslashes($parameters['extension']) : $configuration['extension'];
@@ -131,9 +130,6 @@ class TX_EXTMVC_Dispatcher {
                
                $GLOBALS['TSFE']->additionalHeaderData[$request->getControllerExtensionKey()] = implode("\n", $response->getAdditionalHeaderTags());
                
-               // $time_end = microtime(true);
-               // debug($time_end - $time_start,-1);
-               
                return $response->getContent();
        }