4c29d141c29d76090fb2f665fb9d38e5e82a35ab
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Configuration / ConfigurationManager.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 * A configuration manager following the strategy pattern (GoF315). It hides the concrete
26 * implementation of the configuration manager and provides an unified acccess point.
27 *
28 * Use the shutdown() method to drop the concrete implementation.
29 *
30 * @package Extbase
31 * @subpackage Configuration
32 * @version $ID:$
33 */
34 class Tx_Extbase_Configuration_ConfigurationManager implements Tx_Extbase_Configuration_ConfigurationManagerInterface {
35
36 /**
37 * @var Tx_Extbase_Object_ObjectManagerInterface
38 */
39 protected $objectManager;
40
41 /**
42 * @var Tx_Extbase_Configuration_AbstractConfigurationManager
43 */
44 protected $concreteConfigurationManager;
45
46 /**
47 * @param Tx_Extbase_Object_ObjectManagerInterface $objectManager
48 * @return void
49 */
50 public function injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface $objectManager) {
51 $this->objectManager = $objectManager;
52 $this->initializeConcreteConfigurationManager();
53 }
54
55 /**
56 * @return void
57 */
58 protected function initializeConcreteConfigurationManager() {
59 if (TYPO3_MODE === 'FE') {
60 $this->concreteConfigurationManager = $this->objectManager->get('Tx_Extbase_Configuration_FrontendConfigurationManager');
61 } else {
62 $this->concreteConfigurationManager = $this->objectManager->get('Tx_Extbase_Configuration_BackendConfigurationManager');
63 }
64 }
65
66 /**
67 * @param tslib_cObj $contentObject
68 * @return void
69 */
70 public function setContentObject(tslib_cObj $contentObject = NULL) {
71 $this->concreteConfigurationManager->setContentObject($contentObject);
72 }
73
74 /**
75 * @return tslib_cObj
76 */
77 public function getContentObject() {
78 return $this->concreteConfigurationManager->getContentObject();
79 }
80
81 /**
82 * Sets the specified raw configuration coming from the outside.
83 * Note that this is a low level method and only makes sense to be used by Extbase internally.
84 *
85 * @param array $configuration The new configuration
86 * @return void
87 */
88 public function setConfiguration(array $configuration = array()) {
89 $this->concreteConfigurationManager->setConfiguration($configuration);
90 }
91
92 /**
93 * Returns the specified configuration.
94 * The actual configuration will be merged from different sources in a defined order.
95 *
96 * Note that this is a low level method and only makes sense to be used by Extbase internally.
97 *
98 * @param string $configurationType The kind of configuration to fetch - must be one of the CONFIGURATION_TYPE_* constants
99 * @param string $extensionName if specified, the configuration for the given extension will be returned.
100 * @param string $pluginName if specified, the configuration for the given plugin will be returned.
101 * @return array The configuration
102 */
103 public function getConfiguration($configurationType, $extensionName = NULL, $pluginName = NULL) {
104 switch ($configurationType) {
105 case self::CONFIGURATION_TYPE_SETTINGS:
106 $configuration = $this->concreteConfigurationManager->getConfiguration($extensionName, $pluginName);
107 return $configuration['settings'];
108 case self::CONFIGURATION_TYPE_FRAMEWORK:
109 return $this->concreteConfigurationManager->getConfiguration($extensionName, $pluginName);
110 case self::CONFIGURATION_TYPE_FULL_TYPOSCRIPT:
111 return $this->concreteConfigurationManager->getTypoScriptSetup();
112 default:
113 throw new Tx_Extbase_Configuration_Exception_InvalidConfigurationType(('Invalid configuration type "' . $configurationType) . '"', 1206031879);
114 }
115 }
116
117 /**
118 * Returns TRUE if a certain feature, identified by $featureName
119 * should be activated, FALSE for backwards-compatible behavior.
120 *
121 * This is an INTERNAL API used throughout Extbase and Fluid for providing backwards-compatibility.
122 * Do not use it in your custom code!
123 *
124 * @param string $featureName
125 * @return boolean
126 */
127 public function isFeatureEnabled($featureName) {
128 $configuration = $this->getConfiguration(self::CONFIGURATION_TYPE_FRAMEWORK);
129 return (bool) (isset($configuration['features'][$featureName]) && $configuration['features'][$featureName]);
130 }
131
132 }
133
134 ?>