2 /***************************************************************
5 * (c) 2009 Christian Müller <christian@kitsunet.de>
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.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
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.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
26 * Utilities to manage and convert Typoscript Code
33 class Tx_Extbase_Utility_TypoScript
{
36 * Removes all trailing dots recursively from TS settings array
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.
41 * @param array $settings The settings array
45 public static function convertTypoScriptArrayToPlainArray(array $settings) {
46 foreach ($settings as $key => &$value) {
47 if(substr($key, -1) === '.') {
48 $keyWithoutDot = substr($key, 0, -1);
49 $hasNodeWithoutDot = array_key_exists($keyWithoutDot, $settings);
50 $typoScriptNodeValue = $hasNodeWithoutDot ?
$settings[$keyWithoutDot] : NULL;
51 if(is_array($value)) {
52 $settings[$keyWithoutDot] = self
::convertTypoScriptArrayToPlainArray($value);
53 if(!is_null($typoScriptNodeValue)) {
54 $settings[$keyWithoutDot]['_typoScriptNodeValue'] = $typoScriptNodeValue;
56 unset($settings[$key]);
58 $settings[$keyWithoutDot] = NULL;
66 * Returns an array with Typoscript the old way (with dot).
68 * Extbase converts the "classical" TypoScript (with trailing dot) to a format without trailing dot,
69 * to be more future-proof and not to have any conflicts with Fluid object accessor syntax.
70 * However, if you want to call legacy TypoScript objects, you somehow need the "old" syntax (because this is what TYPO3 is used to).
71 * With this method, you can convert the extbase TypoScript to classical TYPO3 TypoScript which is understood by the rest of TYPO3.
73 * @param array $plainArray An Typoscript Array with Extbase Syntax (without dot but with _typoScriptNodeValue)
74 * @return array array with Typoscript as usual (with dot)
77 public static function convertPlainArrayToTypoScriptArray($plainArray) {
78 $typoScriptArray = array();
79 if (is_array($plainArray)) {
80 foreach ($plainArray as $key => $value) {
81 if (is_array($value)) {
82 if (isset($value['_typoScriptNodeValue'])) {
83 $typoScriptArray[$key] = $value['_typoScriptNodeValue'];
84 unset($value['_typoScriptNodeValue']);
86 $typoScriptArray[$key.'.'] = Tx_Extbase_Utility_TypoScript
::convertPlainArrayToTypoScriptArray($value);
88 $typoScriptArray[$key] = $value;
92 return $typoScriptArray;