[CLEANUP] Adjust code to coding guidelines
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Configuration / ConfigurationManager.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Configuration;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2012 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * A configuration manager following the strategy pattern (GoF315). It hides the concrete
31 * implementation of the configuration manager and provides an unified acccess point.
32 *
33 * Use the shutdown() method to drop the concrete implementation.
34 */
35 class ConfigurationManager implements \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface {
36
37 /**
38 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
39 */
40 protected $objectManager;
41
42 /**
43 * @var \TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
44 */
45 protected $concreteConfigurationManager;
46
47 /**
48 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
49 * @return void
50 */
51 public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) {
52 $this->objectManager = $objectManager;
53 $this->initializeConcreteConfigurationManager();
54 }
55
56 /**
57 * @return void
58 */
59 protected function initializeConcreteConfigurationManager() {
60 if (TYPO3_MODE === 'FE') {
61 $this->concreteConfigurationManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\FrontendConfigurationManager');
62 } else {
63 $this->concreteConfigurationManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\BackendConfigurationManager');
64 }
65 }
66
67 /**
68 * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject
69 * @return void
70 */
71 public function setContentObject(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject = NULL) {
72 $this->concreteConfigurationManager->setContentObject($contentObject);
73 }
74
75 /**
76 * @return \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
77 */
78 public function getContentObject() {
79 return $this->concreteConfigurationManager->getContentObject();
80 }
81
82 /**
83 * Sets the specified raw configuration coming from the outside.
84 * Note that this is a low level method and only makes sense to be used by Extbase internally.
85 *
86 * @param array $configuration The new configuration
87 * @return void
88 */
89 public function setConfiguration(array $configuration = array()) {
90 $this->concreteConfigurationManager->setConfiguration($configuration);
91 }
92
93 /**
94 * Returns the specified configuration.
95 * The actual configuration will be merged from different sources in a defined order.
96 *
97 * You can get the following types of configuration invoking:
98 * CONFIGURATION_TYPE_EXTBASE: Extbase settings
99 * CONFIGURATION_TYPE_FRAMEWORK: the current module/plugin settings
100 * CONFIGURATION_TYPE_TYPOSCRIPT: a raw TS array
101 *
102 * Note that this is a low level method and only makes sense to be used by Extbase internally.
103 *
104 * @param string $configurationType The kind of configuration to fetch - must be one of the CONFIGURATION_TYPE_* constants
105 * @param string $extensionName if specified, the configuration for the given extension will be returned.
106 * @param string $pluginName if specified, the configuration for the given plugin will be returned.
107 * @throws Exception\InvalidConfigurationTypeException
108 * @return array The configuration
109 */
110 public function getConfiguration($configurationType, $extensionName = NULL, $pluginName = NULL) {
111 switch ($configurationType) {
112 case self::CONFIGURATION_TYPE_SETTINGS:
113 $configuration = $this->concreteConfigurationManager->getConfiguration($extensionName, $pluginName);
114 return $configuration['settings'];
115 case self::CONFIGURATION_TYPE_FRAMEWORK:
116 return $this->concreteConfigurationManager->getConfiguration($extensionName, $pluginName);
117 case self::CONFIGURATION_TYPE_FULL_TYPOSCRIPT:
118 return $this->concreteConfigurationManager->getTypoScriptSetup();
119 default:
120 throw new \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException('Invalid configuration type "' . $configurationType . '"', 1206031879);
121 }
122 }
123
124 /**
125 * Returns TRUE if a certain feature, identified by $featureName
126 * should be activated, FALSE for backwards-compatible behavior.
127 *
128 * This is an INTERNAL API used throughout Extbase and Fluid for providing backwards-compatibility.
129 * Do not use it in your custom code!
130 *
131 * @param string $featureName
132 * @return boolean
133 */
134 public function isFeatureEnabled($featureName) {
135 $configuration = $this->getConfiguration(self::CONFIGURATION_TYPE_FRAMEWORK);
136 return (boolean) (isset($configuration['features'][$featureName]) && $configuration['features'][$featureName]);
137 }
138 }
139
140 ?>