[~TASK] Extbase: Reimplemented BE module support. Still needs cleanup.
[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 implements t3lib_Singleton {
33
34 /**
35 * Default backend storage PID
36 */
37 const DEFAULT_BACKEND_STORAGE_PID = 0;
38
39 /**
40 * Storage of the raw TypoScript configuration
41 * @var array
42 */
43 protected $configuration = array();
44
45 /**
46 * @var tslib_cObj
47 */
48 protected $contentObject;
49
50 /**
51 * @var Tx_Extbase_Object_ObjectManagerInterface
52 */
53 protected $objectManager;
54
55 /**
56 * 1st level configuration cache
57 *
58 * @var array
59 */
60 protected $configurationCache = array();
61
62 /**
63 * @param Tx_Extbase_Object_ManagerInterface $objectManager
64 * @return void
65 */
66 public function injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface $objectManager) {
67 $this->objectManager = $objectManager;
68 }
69
70 /**
71 * @param tslib_cObj $contentObject
72 * @return void
73 */
74 public function setContentObject(tslib_cObj $contentObject = NULL) {
75 $this->contentObject = $contentObject;
76 }
77
78 /**
79 * @return tslib_cObj
80 */
81 public function getContentObject() {
82 return $this->contentObject;
83 }
84
85 /**
86 * Sets the specified raw configuration coming from the outside.
87 * Note that this is a low level method and only makes sense to be used by Extbase internally.
88 *
89 * @param array $configuration The new configuration
90 * @return void
91 */
92 public function setConfiguration(array $configuration = array()) {
93 // reset 1st level cache
94 $this->configurationCache = array();
95 $this->configuration = $configuration;
96 }
97
98
99 /**
100 * Returns TypoScript Setup array from current Environment.
101 *
102 * @return array the TypoScript setup
103 */
104 abstract protected function getTypoScriptSetup();
105
106 /**
107 * Resolves the TypoScript reference for $pluginConfiguration[$setting].
108 * In case the setting is a string and starts with "<", we know that this is a TypoScript reference which
109 * needs to be resolved separately.
110 *
111 * @param array $pluginConfiguration The whole plugin configuration
112 * @param string $setting The key inside the $pluginConfiguration to check
113 * @return array The modified plugin configuration
114 */
115 protected function resolveTyposcriptReference($pluginConfiguration, $setting) {
116 if (is_string($pluginConfiguration[$setting]) && substr($pluginConfiguration[$setting], 0, 1) === '<') {
117 $key = trim(substr($pluginConfiguration[$setting], 1));
118 $setup = $this->getTypoScriptSetup();
119 list(, $newValue) = $this->typoScriptParser->getVal($key, $setup);
120
121 unset($pluginConfiguration[$setting]);
122 $pluginConfiguration[$setting . '.'] = $newValue;
123 }
124 return $pluginConfiguration;
125 }
126
127 }
128 ?>