* Adding API annotations to classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Utility / TypoScript.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Christian Müller <christian@kitsunet.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 * Utilities to manage and convert Typoscript Code
27 *
28 * @package Extbase
29 * @subpackage Utility
30 * @version $ID:$
31 * @api
32 */
33 class Tx_Extbase_Utility_TypoScript {
34
35 /**
36 * Removes all trailing dots recursively from TS settings array
37 *
38 * Extbase converts the "classical" TypoScript (with trailing dot) to a format without trailing dot,
39 * to be more future-proof and not to have any conflicts with Fluid object accessor syntax.
40 *
41 * This method performs this removal.
42 *
43 * @param array $setup The settings array
44 * @return void
45 * @api
46 */
47 public static function convertTypoScriptArrayToPlainArray(array $settings) {
48 $processedSettings = array();
49 // TODO Check if the t3lib_div::removeDotsFromTS() fits for this purpose (using rtrim() for removing trailing dots)
50 foreach ($settings as $key => $value) {
51 if (substr($key, -1) === '.') {
52 $keyWithoutDot = substr($key, 0, -1);
53 if (is_array($value)) {
54 $processedSettings[$keyWithoutDot] = self::convertTypoScriptArrayToPlainArray($value);
55 } else {
56 $processedSettings[$keyWithoutDot] = NULL;
57 }
58 if (array_key_exists($keyWithoutDot, $settings)) {
59 $processedSettings[$keyWithoutDot]['_typoScriptNodeValue'] = $settings[$keyWithoutDot];
60 unset($settings[$keyWithoutDot]);
61 }
62 } else {
63 $keyWithDot = $key . '.';
64 if (array_key_exists($keyWithDot, $settings)) {
65 $processedSettings[$key] = self::convertTypoScriptArrayToPlainArray($settings[$keyWithDot]);
66 $processedSettings[$key]['_typoScriptNodeValue'] = $value;
67 unset($settings[$keyWithDot]);
68 } else {
69 $processedSettings[$key] = $value;
70 }
71 }
72 }
73 return $processedSettings;
74 }
75
76 /**
77 * Returns an array with Typoscript the old way (with dot).
78 *
79 * Extbase converts the "classical" TypoScript (with trailing dot) to a format without trailing dot,
80 * to be more future-proof and not to have any conflicts with Fluid object accessor syntax.
81 * However, if you want to call legacy TypoScript objects, you somehow need the "old" syntax (because this is what TYPO3 is used to).
82 * With this method, you can convert the extbase TypoScript to classical TYPO3 TypoScript which is understood by the rest of TYPO3.
83 *
84 * @param array $plainArray An Typoscript Array with Extbase Syntax (without dot but with _typoScriptNodeValue)
85 * @return array array with Typoscript as usual (with dot)
86 * @api
87 */
88 public static function convertPlainArrayToTypoScriptArray($plainArray) {
89 $typoScriptArray = array();
90 if (is_array($plainArray)) {
91 foreach ($plainArray as $key => $value) {
92 if (is_array($value)) {
93 if (isset($value['_typoScriptNodeValue'])) {
94 $typoScriptArray[$key] = $value['_typoScriptNodeValue'];
95 unset($value['_typoScriptNodeValue']);
96 }
97 $typoScriptArray[$key.'.'] = Tx_Extbase_Utility_TypoScript::convertPlainArrayToTypoScriptArray($value);
98 } else {
99 $typoScriptArray[$key] = $value;
100 }
101 }
102 }
103 return $typoScriptArray;
104 }
105 }
106 ?>