eaf443348b408fd734bb098dd204b784b7c5348c
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Configuration / Source / TypoScriptSource.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 * Configuration source based on TS settings
27 *
28 */
29 class Tx_ExtBase_Configuration_Source_TypoScriptSource implements Tx_ExtBase_Configuration_SourceInterface {
30
31 /**
32 * Loads the specified TypoScript configuration file and returns its content in a
33 * configuration container. If the file does not exist or could not be loaded,
34 * the empty configuration container is returned.
35 *
36 * @param string $extensionKey The extension key
37 * @return array The settings as array without trailing dots
38 */
39 public function load($extensionKey) {
40 // SK: same as with dispatcher. strtolower($extensionKey) is wrong; example: tt_news -> tx_ttnews
41 $settings = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_' . strtolower($extensionKey) . '.'];
42 if (is_array($settings)) $settings = $this->postProcessSettings($settings);
43 return $settings;
44 }
45
46 /**
47 * Removes all trailing dots recursively from TS settings array
48 *
49 * @param array $setup The settings array
50 * @return void
51 */
52 protected function postProcessSettings(array $settings) {
53 $processedSettings = array();
54 foreach ($settings as $key => $value) {
55 if (is_array($value)) $value = $this->postProcessSettings($value);
56 $processedSettings[preg_replace('/(.*)\.$/', '\1', $key, 1)] = $value;
57 }
58 return $processedSettings;
59 }
60
61 }
62 ?>