[!!!][~TASK] Extbase (Configuration): Major rework of the ConfigurationManager
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Configuration / AbstractConfigurationManager.php
index 7dab028..e8c5e84 100644 (file)
@@ -47,13 +47,6 @@ abstract class Tx_Extbase_Configuration_AbstractConfigurationManager implements
         */
        protected $contentObject;
 
-       /**
-        * The TypoScript parser
-        *
-        * @var t3lib_TSparser
-        */
-       protected $typoScriptParser;
-
        /**
         * @var Tx_Extbase_Object_ObjectManagerInterface
         */
@@ -84,7 +77,6 @@ abstract class Tx_Extbase_Configuration_AbstractConfigurationManager implements
         */
        public function injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface $objectManager) {
                $this->objectManager = $objectManager;
-               $this->typoScriptParser = t3lib_div::makeInstance('t3lib_TSparser');
        }
 
        /**
@@ -115,7 +107,7 @@ abstract class Tx_Extbase_Configuration_AbstractConfigurationManager implements
 
                $this->extensionName = $configuration['extensionName'];
                $this->pluginName = $configuration['pluginName'];
-               $this->configuration = $configuration;
+               $this->configuration = Tx_Extbase_Utility_TypoScript::convertTypoScriptArrayToPlainArray($configuration);
        }
 
        /**
@@ -131,10 +123,10 @@ abstract class Tx_Extbase_Configuration_AbstractConfigurationManager implements
        public function getConfiguration($extensionName = NULL, $pluginName = NULL) {
                // 1st level cache
                if ($extensionName !== NULL) {
-                       $configurationCacheKey = strtolower($extensionName);
-                       if ($pluginName !== NULL) {
-                               $configurationCacheKey .= '_' . strtolower($pluginName);
+                       if ($pluginName === NULL) {
+                               throw new Tx_Extbase_Configuration_Exception('You\'ll have to specify either both, extensionName and pluginName, or neither.', 1289852422);
                        }
+                       $configurationCacheKey = strtolower($extensionName . '_' . $pluginName);
                } else {
                        $configurationCacheKey = strtolower($this->extensionName . '_' . $this->pluginName);
                }
@@ -142,41 +134,23 @@ abstract class Tx_Extbase_Configuration_AbstractConfigurationManager implements
                        return $this->configurationCache[$configurationCacheKey];
                }
 
-               $frameworkConfiguration = array();
-               $frameworkConfiguration['persistence']['storagePid'] = self::DEFAULT_BACKEND_STORAGE_PID;
+               $frameworkConfiguration = $this->getExtbaseConfiguration();
+               if (!isset($frameworkConfiguration['persistence']['storagePid'])) {
+                       $frameworkConfiguration['persistence']['storagePid'] = self::DEFAULT_BACKEND_STORAGE_PID;
+               }
 
-               $setup = $this->getTypoScriptSetup();
                if ($extensionName !== NULL) {
-                       $pluginConfiguration = $setup['plugin.']['tx_' . strtolower($extensionName) . '.'];
-                       if ($pluginName !== NULL) {
-                               $pluginSignature = strtolower($extensionName . '_' . $pluginName);
-                               if (is_array($setup['plugin.']['tx_' . $pluginSignature . '.'])) {
-                                       $pluginConfiguration = t3lib_div::array_merge_recursive_overrule($pluginConfiguration, $setup['plugin.']['tx_' . $pluginSignature . '.']);
-                               }
-                       }
+                       $pluginConfiguration = $this->getPluginConfiguration($extensionName, $pluginName);
+                       $pluginConfiguration['controllerConfiguration'] = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName][$pluginName]['controllers'];
                } else {
-                       $pluginConfiguration = $this->configuration;
-               }
-               $extbaseConfiguration = $setup['config.']['tx_extbase.'];
-               if (is_array($extbaseConfiguration)) {
-                       $extbaseConfiguration = Tx_Extbase_Utility_TypoScript::convertTypoScriptArrayToPlainArray($extbaseConfiguration);
-                       $frameworkConfiguration = t3lib_div::array_merge_recursive_overrule($frameworkConfiguration, $extbaseConfiguration);
-               }
-
-               if (isset($pluginConfiguration['settings'])) {
-                       $pluginConfiguration = $this->resolveTyposcriptReference($pluginConfiguration, 'settings');
-               }
-               if (!is_array($pluginConfiguration['settings.'])) $pluginConfiguration['settings.'] = array(); // We expect that the settings are arrays on various places
-               if (isset($pluginConfiguration['persistence'])) {
-                       $pluginConfiguration = $this->resolveTyposcriptReference($pluginConfiguration, 'persistence');
-               }
-               if (isset($pluginConfiguration['view'])) {
-                       $pluginConfiguration = $this->resolveTyposcriptReference($pluginConfiguration, 'view');
-               }
-               if (isset($pluginConfiguration['_LOCAL_LANG'])) {
-                       $pluginConfiguration = $this->resolveTyposcriptReference($pluginConfiguration, '_LOCAL_LANG');
+                       $pluginConfiguration = $this->getPluginConfiguration($this->extensionName, $this->pluginName);
+                       $pluginConfiguration = t3lib_div::array_merge_recursive_overrule($pluginConfiguration, $this->configuration);
+                       $pluginConfiguration['controllerConfiguration'] = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$this->extensionName][$this->pluginName]['controllers'];
+                       if (isset($this->configuration['switchableControllerActions'])) {
+                               $this->overrideSwitchableControllerActions($pluginConfiguration, $this->configuration['switchableControllerActions']);
+                       }
                }
-               $frameworkConfiguration = t3lib_div::array_merge_recursive_overrule($frameworkConfiguration, Tx_Extbase_Utility_TypoScript::convertTypoScriptArrayToPlainArray($pluginConfiguration));
+               $frameworkConfiguration = t3lib_div::array_merge_recursive_overrule($frameworkConfiguration, $pluginConfiguration);
 
                // only load context specific configuration when retrieving configuration of the current plugin
                if ($extensionName === NULL || ($extensionName === $this->extensionName && $pluginName === $this->pluginName)) {
@@ -188,6 +162,59 @@ abstract class Tx_Extbase_Configuration_AbstractConfigurationManager implements
                return $frameworkConfiguration;
        }
 
+       /**
+        * Returns the TypoScript configuration found in config.tx_extbase
+        *
+        * @return array
+        */
+       protected function getExtbaseConfiguration() {
+               $setup = $this->getTypoScriptSetup();
+               $extbaseConfiguration = array();
+               if (isset($setup['config.']['tx_extbase.'])) {
+                       $extbaseConfiguration = Tx_Extbase_Utility_TypoScript::convertTypoScriptArrayToPlainArray($setup['config.']['tx_extbase.']);
+               }
+               return $extbaseConfiguration;
+       }
+
+       /**
+        * Returns the TypoScript configuration found in plugin.tx_yourextension_yourplugin
+        * merged with the global configuration of your extension from plugin.tx_yourextension
+        *
+        * @param string $extensionName
+        * @param string $pluginName
+        * @return array
+        */
+       protected function getPluginConfiguration($extensionName, $pluginName) {
+               $setup = $this->getTypoScriptSetup();
+               $pluginConfiguration = array();
+               if (is_array($setup['plugin.']['tx_' . strtolower($extensionName) . '.'])) {
+                       $pluginConfiguration = Tx_Extbase_Utility_TypoScript::convertTypoScriptArrayToPlainArray($setup['plugin.']['tx_' . strtolower($extensionName) . '.']);
+               }
+               $pluginSignature = strtolower($extensionName . '_' . $pluginName);
+               if (is_array($setup['plugin.']['tx_' . $pluginSignature . '.'])) {
+                       $pluginConfiguration = t3lib_div::array_merge_recursive_overrule($pluginConfiguration, Tx_Extbase_Utility_TypoScript::convertTypoScriptArrayToPlainArray($setup['plugin.']['tx_' . $pluginSignature . '.']));
+               }
+               return $pluginConfiguration;
+       }
+
+       /**
+        * @param array $frameworkConfiguration
+        * @param array $overriddenSwitchableControllerActions in the format array('Controller1' => array('action1', 'action2'), 'Controller2' => ...)
+        * @return void
+        */
+       protected function overrideSwitchableControllerActions(array &$frameworkConfiguration, array $switchableControllerActions) {
+               $overriddenSwitchableControllerActions = array();
+               foreach ($switchableControllerActions as $controllerName => $actions) {
+                       $overriddenSwitchableControllerActions[$controllerName] = array('actions' => $actions);
+                       $nonCacheableActions = $frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'];
+                       $overriddenNonCacheableActions = array_intersect($nonCacheableActions, $actions);
+                       if (!empty($overriddenNonCacheableActions)) {
+                               $overriddenSwitchableControllerActions[$controllerName]['nonCacheableActions'] = $overriddenNonCacheableActions;
+                       }
+               }
+               $frameworkConfiguration['controllerConfiguration'] = $overriddenSwitchableControllerActions;
+       }
+
        /**
         * The context specific configuration returned by this method
         * will override the framework configuration which was
@@ -199,7 +226,7 @@ abstract class Tx_Extbase_Configuration_AbstractConfigurationManager implements
         * @param array $frameworkConfiguration The framework configuration until now
         * @return array context specific configuration which will override the configuration obtained by TypoScript
         */
-       abstract protected function getContextSpecificFrameworkConfiguration($frameworkConfiguration);
+       abstract protected function getContextSpecificFrameworkConfiguration(array $frameworkConfiguration);
 
        /**
         * Returns TypoScript Setup array from current Environment.
@@ -207,26 +234,5 @@ abstract class Tx_Extbase_Configuration_AbstractConfigurationManager implements
         * @return array the TypoScript setup
         */
        abstract protected function getTypoScriptSetup();
-
-       /**
-        * 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) === '<') {
-                       $key = trim(substr($pluginConfiguration[$setting], 1));
-                       $setup = $this->getTypoScriptSetup();
-                       list(, $newValue) = $this->typoScriptParser->getVal($key, $setup);
-
-                       unset($pluginConfiguration[$setting]);
-                       $pluginConfiguration[$setting . '.'] = $newValue;
-               }
-               return $pluginConfiguration;
-       }
 }
 ?>
\ No newline at end of file