d4d1a56642cf10d33dc76c9defa32f457b182fc9
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Configuration / Manager.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 require_once(PATH_t3lib . 'interfaces/interface.t3lib_singleton.php');
26
27 /**
28 * A general purpose configuration manager
29 *
30 * @package TYPO3
31 * @subpackage extbase
32 * @version $ID:$
33 */
34 class Tx_ExtBase_Configuration_Manager implements t3lib_Singleton {
35
36 /**
37 * Storage for the settings, loaded by loadGlobalSettings()
38 *
39 * @var array
40 */
41 protected $settings = array();
42
43 /**
44 * The configuration source instances used for loading the raw configuration
45 *
46 * @var array
47 */
48 protected $configurationSources;
49
50 /**
51 * Constructs the configuration manager
52 *
53 * @param array $configurationSourcesObjectNames An array of object names of the configuration sources
54 */
55 public function __construct(array $configurationSources) {
56 $this->configurationSources = $configurationSources;
57 }
58
59 /**
60 * Returns an array with the settings defined for the specified extension.
61 *
62 * @param string $extensionKey Key of the extension to return the settings for
63 * @return array The settings of the specified extension
64 */
65 public function getSettings($extensionKey, $controllerName = '', $actionName = '') {
66 $settings = array();
67 if (is_array($this->settings[$extensionKey])) {
68 $settings = $this->settings[$extensionKey];
69 if (!empty($controllerName) && is_array($settings[$controllerName])) {
70 if (!empty($actionName) && is_array($settings[$controllerName][$actionName])) {
71 $settings = $settings[$controllerName][$actionName];
72 } else {
73 $settings = $settings[$controllerName];
74 }
75 }
76 // SK: TODO: Look at this in detail
77 // JR: This is an overlay of TS settings; "local" values overwrite more "global" values
78 // TODO Should we provide a hierarchical TS setting overlay?
79 // if (!empty($controllerName) && is_array($settings[$controllerName])) {
80 // foreach ($settings[$controllerName] as $key => $value) {
81 // if (array_key_exists($key, $settings)) {
82 // $settings[$key] = $value;
83 // }
84 // }
85 // }
86 // if (!empty($actionName) && is_array($settings[$controllerName][$actionName])) {
87 // foreach ($settings[$controllerName][$actionName] as $key => $value) {
88 // if (array_key_exists($key, $settings)) {
89 // $settings[$key] = $value;
90 // }
91 // if (array_key_exists($key, $settings[$controllerName])) {
92 // $settings[$controllerName][$key] = $value;
93 // }
94 // }
95 // }
96 }
97 return $settings;
98 }
99
100 /**
101 * Loads the settings defined in the specified extensions and merges them with
102 * those potentially existing in the global configuration folders.
103 *
104 * The result is stored in the configuration manager's settings registry
105 * and can be retrieved with the getSettings() method.
106 *
107 * @param string $extensionKey
108 * @return void
109 * @see getSettings()
110 */
111 public function loadGlobalSettings($extensionKey) {
112 $settings = $this->settings[$extensionKey];
113 if (empty($settings)) $settings = array();
114 foreach ($this->configurationSources as $configurationSource) {
115 $settings = t3lib_div::array_merge_recursive_overrule($settings, $configurationSource->load($extensionKey));
116 }
117 $this->settings[$extensionKey] = $settings;
118 }
119
120 }
121 ?>