[!!!][BUGFIX] Extbase (Configuration): Moved _LOCAL_LANG from plugin.tx_XXX.settings...
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Configuration / AbstractConfigurationManager.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Abstract base class for a general purpose configuration manager
27 *
28 * @package Extbase
29 * @subpackage Configuration
30 * @version $ID:$
31 */
32 abstract class Tx_Extbase_Configuration_AbstractConfigurationManager {
33
34 /**
35 * Default backend storage PID
36 */
37 const DEFAULT_BACKEND_STORAGE_PID = 0;
38
39 /**
40 * The TypoScript parser
41 *
42 * @var t3lib_TSparser
43 */
44 protected $typoScriptParser;
45
46 /**
47 * Storage for the settings, loaded by loadSettings()
48 *
49 * @var array
50 */
51 protected $settings;
52
53 /**
54 * The configuration source instances used for loading the raw configuration
55 *
56 * @var array
57 */
58 protected $configurationSources = array();
59
60 /**
61 * Constructs the configuration manager
62 *
63 * @param array $configurationSources An array of configuration sources
64 */
65 public function __construct($configurationSources = NULL) {
66 $this->typoScriptParser = t3lib_div::makeInstance('t3lib_TSparser');
67 if (is_array($configurationSources)) {
68 $this->configurationSources = $configurationSources;
69 }
70 }
71
72 /**
73 * Returns an array with the settings defined for the specified extension.
74 *
75 * @param string $extensionName Name of the extension to return the settings for
76 * @return array The settings of the specified extension
77 */
78 public function getSettings($extensionName) {
79 if (empty($this->settings[$extensionName])) {
80 $this->loadSettings($extensionName);
81 }
82 return $this->settings[$extensionName];
83 }
84
85 /**
86 * Loads the Extbase Framework configuration.
87 *
88 * The Extbase framework configuration HAS TO be retrieved using this method, as they are come from different places than the normal settings.
89 * Framework configuration is, in contrast to normal settings, needed for the Extbase framework to operate correctly.
90 *
91 * @param array $pluginConfiguration The current incoming extbase configuration
92 * @return array the Extbase framework configuration
93 */
94 public function getFrameworkConfiguration($pluginConfiguration) {
95 $frameworkConfiguration = array();
96 $frameworkConfiguration['persistence']['storagePid'] = self::DEFAULT_BACKEND_STORAGE_PID;
97
98 $setup = $this->loadTypoScriptSetup();
99 $extbaseConfiguration = $setup['config.']['tx_extbase.'];
100 if (is_array($extbaseConfiguration)) {
101 $extbaseConfiguration = Tx_Extbase_Utility_TypoScript::convertTypoScriptArrayToPlainArray($extbaseConfiguration);
102 $frameworkConfiguration = t3lib_div::array_merge_recursive_overrule($frameworkConfiguration, $extbaseConfiguration);
103 }
104
105 if (isset($pluginConfiguration['settings'])) {
106 $pluginConfiguration = $this->resolveTyposcriptReference($pluginConfiguration, 'settings');
107 }
108 if (isset($pluginConfiguration['persistence'])) {
109 $pluginConfiguration = $this->resolveTyposcriptReference($pluginConfiguration, 'persistence');
110 }
111 if (isset($pluginConfiguration['view'])) {
112 $pluginConfiguration = $this->resolveTyposcriptReference($pluginConfiguration, 'view');
113 }
114 if (isset($pluginConfiguration['_LOCAL_LANG'])) {
115 $pluginConfiguration = $this->resolveTyposcriptReference($pluginConfiguration, '_LOCAL_LANG');
116 }
117 $frameworkConfiguration = t3lib_div::array_merge_recursive_overrule($frameworkConfiguration, Tx_Extbase_Utility_TypoScript::convertTypoScriptArrayToPlainArray($pluginConfiguration));
118
119 $frameworkConfiguration = t3lib_div::array_merge_recursive_overrule($frameworkConfiguration, $this->getContextSpecificFrameworkConfiguration());
120 return $frameworkConfiguration;
121 }
122
123 /**
124 * The context specific configuration returned by this method
125 * will override the framework configuration which was
126 * obtained from TypoScript. This can be used f.e. to override the storagePid
127 * with the value set inside the Plugin Instance.
128 *
129 * WARNING: Make sure this method ALWAYS returns an array!
130 *
131 * @return array context specific configuration which will override the configuration obtained by TypoScript
132 */
133 abstract protected function getContextSpecificFrameworkConfiguration();
134
135 /**
136 * Returns TypoScript Setup array from current Environment.
137 *
138 * @return array the TypoScript setup
139 */
140 abstract public function loadTypoScriptSetup();
141
142 /**
143 * Resolves the TypoScript reference for $pluginConfiguration[$setting].
144 * In case the setting is a string and starts with "<", we know that this is a TypoScript reference which
145 * needs to be resolved separately.
146 *
147 * @param array $pluginConfiguration The whole plugin configuration
148 * @param string $setting The key inside the $pluginConfiguration to check
149 * @return array The modified plugin configuration
150 */
151 protected function resolveTyposcriptReference($pluginConfiguration, $setting) {
152 if (is_string($pluginConfiguration[$setting]) && substr($pluginConfiguration[$setting], 0, 1) === '<') {
153 $key = trim(substr($pluginConfiguration[$setting], 1));
154 $setup = $this->loadTypoScriptSetup();
155 list(, $newValue) = $this->typoScriptParser->getVal($key, $setup);
156
157 unset($pluginConfiguration[$setting]);
158 $pluginConfiguration[$setting . '.'] = $newValue;
159 }
160 return $pluginConfiguration;
161 }
162
163 /**
164 * Loads the settings defined in the specified extensions and merges them with
165 * those potentially existing in the global configuration folders.
166 *
167 * The result is stored in the configuration manager's settings registry
168 * and can be retrieved with the getSettings() method.
169 *
170 * @param string $extensionName
171 * @return void
172 * @see getSettings()
173 */
174 protected function loadSettings($extensionName) {
175 $settings = array();
176 foreach ($this->configurationSources as $configurationSource) {
177 $settings = t3lib_div::array_merge_recursive_overrule($settings, $configurationSource->load($extensionName));
178 }
179 $this->settings[$extensionName] = $settings;
180 }
181
182
183 }
184 ?>