[!!!][+FEATURE] Extbase (Settings): Custom settings now reside in plugin.tx_extension...
authorSebastian Kurfürst <sebastian@typo3.org>
Thu, 6 Aug 2009 21:01:16 +0000 (21:01 +0000)
committerSebastian Kurfürst <sebastian@typo3.org>
Thu, 6 Aug 2009 21:01:16 +0000 (21:01 +0000)
[!!!][+FEATURE] Extbase (Settings): Persistence settings now reside in plugin.tx_extensionnname.persistence instead of tt_content.list.20. ... THIS IS A BREAKING CHANGE, but of a really new feature. Resolves #4177
[!!!]?\027[TASK] Extbase (Dispatcher): Renamed Tx_Extbase_Dispatcher::getSettings() to Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration(). THIS IS A BREAKING CHANGE, but of a non-public API. Related to #4177
[TASK] Extbase (Configuration): Cleaned up configuration manager and renamed methods there.

typo3/sysext/extbase/Classes/Configuration/Manager.php
typo3/sysext/extbase/Classes/Configuration/Source/TypoScriptSource.php
typo3/sysext/extbase/Classes/Dispatcher.php
typo3/sysext/extbase/Classes/Persistence/Backend.php
typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php
typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php
typo3/sysext/extbase/Classes/Utility/Plugin.php
typo3/sysext/extbase/ext_typoscript_setup.txt

index 95186ad..705a7b2 100644 (file)
@@ -39,7 +39,7 @@ class Tx_Extbase_Configuration_Manager {
        const DEFAULT_BACKEND_STORAGE_PID = 0;
 
        /**
-        * Storage for the settings, loaded by loadGlobalSettings()
+        * Storage for the settings, loaded by loadSettings()
         *
         * @var array
         */
@@ -71,37 +71,78 @@ class Tx_Extbase_Configuration_Manager {
         */
        public function getSettings($extensionName) {
                if (empty($this->settings[$extensionName])) {
-                       $this->loadGlobalSettings($extensionName);
+                       $this->loadSettings($extensionName);
                }
                return $settings = $this->settings[$extensionName];
        }
 
        /**
-        * Loads the Extbase core settings.
+        * Loads the settings defined in the specified extensions and merges them with
+        * those potentially existing in the global configuration folders.
         *
-        * The Extbase 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 package's settings.
+        * The result is stored in the configuration manager's settings registry
+        * and can be retrieved with the getSettings() method.
         *
-        * @param array $configuration The current incoming extbase configuration
-        * @param tslib_cObj $cObj The current Content Object
+        * @param string $extensionName
         * @return void
+        * @see getSettings()
         */
-       public function loadExtbaseSettings($configuration, $cObj) {
+       protected function loadSettings($extensionName) {
                $settings = array();
-               $settings['storagePid'] = $this->getDefaultStoragePageId($cObj);
-               $settings['contentObjectData'] = $cObj->data;
+               foreach ($this->configurationSources as $configurationSource) {
+                       $settings = t3lib_div::array_merge_recursive_overrule($settings, $configurationSource->load($extensionName));
+               }
+               $this->settings[$extensionName] = $settings;
+       }
+
+       /**
+        * Loads the Extbase Framework configuration.
+        *
+        * The Extbase framework configuration HAS TO be retrieved using this method, as they are come from different places than the normal settings.
+        * Framework configuration is, in contrast to normal settings, needed for the Extbase framework to operate correctly.
+        *
+        * @param array $pluginConfiguration The current incoming extbase configuration
+        * @param tslib_cObj $cObj The current Content Object
+        * @return array the Extbase framework configuration
+        */
+       public function getFrameworkConfiguration($pluginConfiguration, $cObj) {
+               $frameworkConfiguration = array();
+               $frameworkConfiguration['persistence']['storagePid'] = $this->getDefaultStoragePageId($cObj);
+               $frameworkConfiguration['contentObjectData'] = $cObj->data;
+
                // TODO Support BE modules by parsing the file "manually" and all files EXT:myext/Configuration/Objects/setup.txt
                $extbaseConfiguration = $GLOBALS['TSFE']->tmpl->setup['config.']['tx_extbase.'];
                if (is_array($extbaseConfiguration)) {
                        $extbaseConfiguration = Tx_Extbase_Configuration_Manager::postProcessSettings($extbaseConfiguration);
-               } else {
-                       $extbaseConfiguration = array();
+                       $frameworkConfiguration = t3lib_div::array_merge_recursive_overrule($frameworkConfiguration, $extbaseConfiguration);
                }
-               $settings = t3lib_div::array_merge_recursive_overrule($settings, $extbaseConfiguration);
-               $settings = t3lib_div::array_merge_recursive_overrule($settings, self::postProcessSettings($configuration));
 
-               $this->settings['Extbase'] = $settings;
+               if (isset($pluginConfiguration['persistence'])) {
+                       $pluginConfiguration = $this->resolveTyposcriptReference($pluginConfiguration, 'persistence');
+               }
+               $frameworkConfiguration = t3lib_div::array_merge_recursive_overrule($frameworkConfiguration, self::postProcessSettings($pluginConfiguration));
+               return $frameworkConfiguration;
+       }
+
+       /**
+        * Resolves the TypoScript reference for $pluginConfiguration[$setting].
+        * In case the setting is a string and starts with "<", we know that this is a TypoScript reference which
+        * needs to be resolved separately.
+        *
+        * @param array $pluginConfiguration The whole plugin configuration
+        * @param string $setting The key inside the $pluginConfiguration to check
+        * @return array The modified plugin configuration
+        */
+       protected function resolveTyposcriptReference($pluginConfiguration, $setting) {
+               if (is_string($pluginConfiguration[$setting]) && substr($pluginConfiguration[$setting], 0, 1) === '<') {
+                       $typoScriptParser = t3lib_div::makeInstance('t3lib_TSparser');
+                       $key = trim(substr($pluginConfiguration[$setting], 1));
+                       list(, $newValue) = $typoScriptParser->getVal($key,$GLOBALS['TSFE']->tmpl->setup);
+
+                       unset($pluginConfiguration[$setting]);
+                       $pluginConfiguration[$setting . '.'] = $newValue;
+               }
+               return $pluginConfiguration;
        }
 
        /**
@@ -135,25 +176,6 @@ class Tx_Extbase_Configuration_Manager {
        }
 
        /**
-        * Loads the settings 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 settings registry
-        * and can be retrieved with the getSettings() method.
-        *
-        * @param string $extensionName
-        * @return void
-        * @see getSettings()
-        */
-       protected function loadGlobalSettings($extensionName) {
-               $settings = array();
-               foreach ($this->configurationSources as $configurationSource) {
-                       $settings = t3lib_div::array_merge_recursive_overrule($settings, $configurationSource->load($extensionName));
-               }
-               $this->settings[$extensionName] = $settings;
-       }
-
-       /**
         * Removes all trailing dots recursively from TS settings array
         * TODO Explain why we remove the dots.
         *
index 9740c5a..8e900f8 100644 (file)
@@ -44,7 +44,7 @@ class Tx_Extbase_Configuration_Source_TypoScriptSource implements Tx_Extbase_Con
         */
         public function load($extensionName) {
                // TODO Needs a FE (does actually not work with BE or CLI)
-               $settings = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_' . strtolower($extensionName) . '.'];
+               $settings = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_' . strtolower($extensionName) . '.']['settings.'];
                if (is_array($settings)) {
                        $settings = Tx_Extbase_Configuration_Manager::postProcessSettings($settings);
                } else {
index b3bd546..788dc62 100644 (file)
@@ -49,10 +49,10 @@ class Tx_Extbase_Dispatcher {
        private static $persistenceManager;
 
        /**
-        * The settings for the Extbase framework
+        * The configuration for the Extbase framework
         * @var array
         */
-       private static $settings;
+       private static $extbaseFrameworkConfiguration;
 
 
        /**
@@ -70,7 +70,6 @@ class Tx_Extbase_Dispatcher {
         * @return string $content The processed content
         */
        public function dispatch($content, $configuration) {
-
                // FIXME Remove the next lines. These are only there to generate the ext_autoload.php file
                //$extutil = new Tx_Extbase_Utility_Extension;
                //$extutil->createAutoloadRegistryForExtension('extbase', t3lib_extMgm::extPath('extbase'));
@@ -80,14 +79,14 @@ class Tx_Extbase_Dispatcher {
                        t3lib_div::sysLog('Extbase was not able to dispatch the request. No configuration.', 'extbase', t3lib_div::SYSLOG_SEVERITY_ERROR);
                        return $content;
                }
-               $this->initializeConfiguration($configuration);
+               $this->initializeConfigurationManagerAndFrameworkConfiguration($configuration);
 
                $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');
 
-               $persistenceManager = self::getPersistenceManager($configuration);
+               $persistenceManager = self::getPersistenceManager();
 
                $dispatchLoopCount = 0;
                while (!$request->isDispatched()) {
@@ -116,7 +115,7 @@ class Tx_Extbase_Dispatcher {
         * @param $configuration The current incoming configuration
         * @return void
         */
-       protected function initializeConfiguration($configuration) {
+       protected function initializeConfigurationManagerAndFrameworkConfiguration($configuration) {
                $configurationSources = array();
                $configurationSources[] = t3lib_div::makeInstance('Tx_Extbase_Configuration_Source_TypoScriptSource');
                if (!empty($this->cObj->data['pi_flexform'])) {
@@ -125,8 +124,7 @@ class Tx_Extbase_Dispatcher {
                        $configurationSources[] = $configurationSource;
                }
                $this->configurationManager = t3lib_div::makeInstance('Tx_Extbase_Configuration_Manager', $configurationSources);
-               $this->configurationManager->loadExtbaseSettings($configuration, $this->cObj);
-               self::$settings = $this->configurationManager->getSettings('Extbase');
+               self::$extbaseFrameworkConfiguration = $this->configurationManager->getFrameworkConfiguration($configuration, $this->cObj);
        }
 
        /**
@@ -173,10 +171,9 @@ class Tx_Extbase_Dispatcher {
        /**
         * This function prepares and returns the Persistance Manager
         *
-        * @param array $configuration The given configuration
         * @return Tx_Extbase_Persistence_Manager A (singleton) instance of the Persistence Manager
         */
-       public static function getPersistenceManager(array $configuration = array()) {
+       public static function getPersistenceManager() {
                if (self::$persistenceManager === NULL) {
                        $queryFactory = t3lib_div::makeInstance('Tx_Extbase_Persistence_QueryFactory'); // singleton
 
@@ -184,12 +181,7 @@ class Tx_Extbase_Dispatcher {
 
                        $storageBackend = t3lib_div::makeInstance('Tx_Extbase_Persistence_Storage_Typo3DbBackend', $GLOBALS['TYPO3_DB']); // singleton
                        $storageBackend->injectDataMapper($dataMapper);
-                       if (isset($configuration['enableAutomaticCacheClearing']) && $configuration['enableAutomaticCacheClearing'] === '1') {
-                               $storageBackend->setAutomaticCacheClearing(TRUE);
-                       } else {
-                               $storageBackend->setAutomaticCacheClearing(FALSE);
-                       }
-                       
+
                        $persistenceSession = t3lib_div::makeInstance('Tx_Extbase_Persistence_Session'); // singleton
 
                        $persistenceBackend = t3lib_div::makeInstance('Tx_Extbase_Persistence_Backend', $persistenceSession, $storageBackend); // singleton
@@ -213,11 +205,10 @@ class Tx_Extbase_Dispatcher {
         *
         * @return array The settings
         */
-       public static function getSettings() {
-               return self::$settings;
+       public static function getExtbaseFrameworkConfiguration() {
+               return self::$extbaseFrameworkConfiguration;
        }
 
-
        /**
         * Loads php files containing classes or interfaces found in the classes directory of
         * an extension.
index 4f283a1..7f31691 100644 (file)
@@ -549,12 +549,12 @@ class Tx_Extbase_Persistence_Backend implements Tx_Extbase_Persistence_BackendIn
         */
        protected function determineStoragePageIdForNewRecord(Tx_Extbase_DomainObject_DomainObjectInterface $object) {
                $className = get_class($object);
-               $extbaseSettings = Tx_Extbase_Dispatcher::getSettings();
+               $extbaseSettings = Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration();
 
-               if (isset($extbaseSettings['classes'][$className]) && !empty($extbaseSettings['classes'][$className]['newRecordStoragePid'])) {
-                       return (int)$extbaseSettings['classes'][$className]['newRecordStoragePid'];
+               if (isset($extbaseSettings['persistence']['classes'][$className]) && !empty($extbaseSettings['persistence']['classes'][$className]['newRecordStoragePid'])) {
+                       return (int)$extbaseSettings['persistence']['classes'][$className]['newRecordStoragePid'];
                } else {
-                       $storagePidList = t3lib_div::intExplode(',', $extbaseSettings['storagePid']);
+                       $storagePidList = t3lib_div::intExplode(',', $extbaseSettings['persistence']['storagePid']);
                        return (int) $storagePidList[0];
                }
        }
index 70c91c0..b7954d7 100644 (file)
@@ -307,20 +307,20 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
                        if (empty($this->dataMaps[$className])) {
                                // FIXME This is a costy for table name aliases -> implement a DataMapBuilder (knowing the aliases defined in $TCA)
                                $mapping = array();
-                               $extbaseSettings = Tx_Extbase_Dispatcher::getSettings();
-                               if (isset($extbaseSettings['classes'][$className]) && !empty($extbaseSettings['classes'][$className]['mapping']['tableName'])) {
-                                       $tableName = $extbaseSettings['classes'][$className]['mapping']['tableName'];
+                               $extbaseSettings = Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration();
+                               if (isset($extbaseSettings['persistence']['classes'][$className]) && !empty($extbaseSettings['persistence']['classes'][$className]['mapping']['tableName'])) {
+                                       $tableName = $extbaseSettings['persistence']['classes'][$className]['mapping']['tableName'];
                                } else {
                                        foreach (class_parents($className) as $parentClassName) {
-                                               if (isset($extbaseSettings['classes'][$parentClassName]) && !empty($extbaseSettings['classes'][$parentClassName]['mapping']['tableName'])) {
-                                                       $tableName = $extbaseSettings['classes'][$parentClassName]['mapping']['tableName'];
+                                               if (isset($extbaseSettings['persistence']['classes'][$parentClassName]) && !empty($extbaseSettings['persistence']['classes'][$parentClassName]['mapping']['tableName'])) {
+                                                       $tableName = $extbaseSettings['persistence']['classes'][$parentClassName]['mapping']['tableName'];
                                                        break;
                                                }
                                                // TODO throw Exception
                                        }
                                }
-                               if (is_array($extbaseSettings['classes'][$parentClassName]['mapping']['columns'])) {
-                                       $mapping = $extbaseSettings['classes'][$parentClassName]['mapping']['columns'];
+                               if (is_array($extbaseSettings['persistence']['classes'][$parentClassName]['mapping']['columns'])) {
+                                       $mapping = $extbaseSettings['persistence']['classes'][$parentClassName]['mapping']['columns'];
                                }
 
                                $dataMap = new Tx_Extbase_Persistence_Mapper_DataMap($className, $tableName, $mapping);
index dcf1cad..8f0c3db 100644 (file)
@@ -57,13 +57,6 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
        protected $pageSelectObject;
 
        /**
-        * TRUE if automatic cache clearing in TCEMAIN should be done on insert/update/delete, FALSE otherwise.
-        *
-        * @var boolean
-        */
-       protected $automaticCacheClearing = FALSE;
-
-       /**
         * Constructs this Storage Backend instance
         *
         * @param t3lib_db $databaseHandle The database handle
@@ -71,8 +64,9 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
        public function __construct($databaseHandle) {
                $this->databaseHandle = $databaseHandle;
        }
-       
+
        /**
+
         * Injects the DataMapper to map nodes to objects
         *
         * @param Tx_Extbase_Persistence_Mapper_DataMapper $dataMapper
@@ -83,18 +77,6 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
        }
 
        /**
-        * Set the automatic cache clearing flag.
-        * If TRUE, then inserted/updated/deleted records trigger a TCEMAIN cache clearing.
-        *
-        * @param $automaticCacheClearing boolean if TRUE, enables automatic cache clearing
-        * @return void
-
-        */
-       public function setAutomaticCacheClearing($automaticCacheClearing) {
-               $this->automaticCacheClearing = (boolean)$automaticCacheClearing;
-       }
-
-       /**
         * Adds a row to the storage
         *
         * @param string $tableName The database table name
@@ -217,10 +199,10 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
                        $sql['orderings'] = array();
                        $sql['limit'] = array();
                        $tuples = array();
-                       
+
                        $source = $query->getSource();
                        $this->parseSource($query, $source, $sql, $parameters);
-                       
+
                        $statement = 'SELECT ' . implode(',', $sql['fields']) . ' FROM ' . implode(' ', $sql['tables']);
 
                        $this->parseConstraint($query->getConstraint(), $source, $sql, $parameters, $query->getBoundVariableValues());
@@ -244,7 +226,7 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
                                $statement .= ' LIMIT ' . $sql['limit'];
                        }
                }
-               
+
                $this->replacePlaceholders($statement, $parameters);
 
                return $statement;
@@ -547,8 +529,8 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
        protected function addPageIdStatement($tableName, array &$sql) {
                // TODO We have to call the appropriate API method if we are in TYPO3BE mode
                if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
-                       $extbaseSettings = Tx_Extbase_Dispatcher::getSettings();
-                       $sql['additionalWhereClause'][] = $tableName . '.pid IN (' . implode(', ', t3lib_div::intExplode(',', $extbaseSettings['storagePid'])) . ')';
+                       $extbaseFrameworkConfiguration = Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration();
+                       $sql['additionalWhereClause'][] = $tableName . '.pid IN (' . implode(', ', t3lib_div::intExplode(',', $extbaseFrameworkConfiguration['persistence']['storagePid'])) . ')';
                }
        }
 
@@ -689,7 +671,12 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
         * @return void
         */
        protected function clearPageCache($tableName, $uid) {
-               if ($this->automaticCacheClearing !== TRUE) return;
+               $extbaseSettings = Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration();
+               if (isset($extbaseSettings['persistence']['enableAutomaticCacheClearing']) && $extbaseSettings['persistence']['enableAutomaticCacheClearing'] === '1') {
+               } else {
+                       // if disabled, return
+                       return;
+               }
 
                $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
                $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
index cf1948d..14ac149 100644 (file)
@@ -5,7 +5,7 @@
 *  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
 *  All rights reserved
 *
-*  This class is a backport of the corresponding class of FLOW3. 
+*  This class is a backport of the corresponding class of FLOW3.
 *  All credits go to the v5 team.
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -37,10 +37,10 @@ class Tx_Extbase_Utility_Plugin {
        /**
         * Add auto-generated TypoScript to configure the Extbase Dispatcher.
         *
-        * When adding a frontend plugin you will have to add both an entry to the TCA definition 
+        * When adding a frontend plugin you will have to add both an entry to the TCA definition
         * of tt_content table AND to the TypoScript template which must initiate the rendering.
-        * Since the static template with uid 43 is the "content.default" and practically always 
-        * used for rendering the content elements it's very useful to have this function automatically 
+        * Since the static template with uid 43 is the "content.default" and practically always
+        * used for rendering the content elements it's very useful to have this function automatically
         * adding the necessary TypoScript for calling the appropriate controller and action of your plugin.
         * It will also work for the extension "css_styled_content"
         * FOR USE IN ext_localconf.php FILES
@@ -94,7 +94,7 @@ class Tx_Extbase_Utility_Plugin {
                $nonCachableActions = array();
                if (!empty($nonCachableControllerActions[$defaultController])) {
                        $nonCachableActions = t3lib_div::trimExplode(',', $nonCachableControllerActions[$defaultController]);
-               }               
+               }
                $cachableActions = array_diff(t3lib_div::trimExplode(',', $controllerActions[$defaultController]), $nonCachableActions);
 
                $contentObjectType = in_array($defaultAction, $nonCachableActions) ? 'USER_INT' : 'USER';
@@ -116,16 +116,29 @@ tt_content.list.20.' . $pluginSignature . ' = ' . ($contentObjectType === 'USER'
                        }
                }
 
+               $pluginTemplate = trim('plugin.tx_' . strtolower($extensionName) . '.settings {
+}
+plugin.tx_' . strtolower($extensionName) . '.persistence {
+       enableAutomaticCacheClearing = 1
+       # storagePid
+       classes {
+       }
+}');
+               t3lib_extMgm::addTypoScript($extensionName, 'setup', '
+# Setting ' . $extensionName . ' plugin TypoScript
+' . $pluginTemplate);
+
                $pluginContent = trim('
 tt_content.list.20.' . $pluginSignature . ' = ' . $contentObjectType . '
 tt_content.list.20.' . $pluginSignature . ' {
        userFunc = tx_extbase_dispatcher->dispatch
        pluginName = ' . $pluginName . '
        extensionName = ' . $extensionName . '
-       enableAutomaticCacheClearing = 1' . 
-       $controller .
-       $action . 
+       ' . $controller .
+       $action .
        $switchableControllerActions . '
+
+       persistence =< plugin.tx_' . strtolower($extensionName) . '.persistence
 }
 ' . $conditions);
 
@@ -152,7 +165,7 @@ tt_content.list.20.' . $pluginSignature . ' {
                }
                $extensionName = str_replace(' ', '', ucwords(str_replace('_', ' ', $extensionName)));
                $pluginSignature = strtolower($extensionName) . '_' . strtolower($pluginName);
-               
+
                t3lib_extMgm::addPlugin(array($pluginTitle, $pluginSignature), 'list_type');
        }
 
index 1ae84e9..19dd266 100644 (file)
@@ -7,7 +7,7 @@ config.tx_extbase {
                        }
                }
        }
-       classes {
+       persistence.classes {
                Tx_Extbase_Domain_Model_FrontendUser {
                        mapping {
                                tableName = fe_users