[CLEANUP] Replace wrong/old file copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Service / TypoScriptService.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Service;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2012 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
8 * Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * Utilities to manage and convert TypoScript
32 */
33 class TypoScriptService implements \TYPO3\CMS\Core\SingletonInterface {
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 * @param array $typoScriptArray The TypoScript array (e.g. array('foo' => 'TEXT', 'foo.' => array('bar' => 'baz')))
42 * @return array
43 * @api
44 */
45 public function convertTypoScriptArrayToPlainArray(array $typoScriptArray) {
46 foreach ($typoScriptArray as $key => &$value) {
47 if (substr($key, -1) === '.') {
48 $keyWithoutDot = substr($key, 0, -1);
49 $hasNodeWithoutDot = array_key_exists($keyWithoutDot, $typoScriptArray);
50 $typoScriptNodeValue = $hasNodeWithoutDot ? $typoScriptArray[$keyWithoutDot] : NULL;
51 if (is_array($value)) {
52 $typoScriptArray[$keyWithoutDot] = $this->convertTypoScriptArrayToPlainArray($value);
53 if (!is_null($typoScriptNodeValue)) {
54 $typoScriptArray[$keyWithoutDot]['_typoScriptNodeValue'] = $typoScriptNodeValue;
55 }
56 unset($typoScriptArray[$key]);
57 } else {
58 $typoScriptArray[$keyWithoutDot] = NULL;
59 }
60 }
61 }
62 return $typoScriptArray;
63 }
64
65 /**
66 * Returns an array with Typoscript the old way (with dot).
67 *
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.
72 *
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)
75 * @api
76 */
77 public function convertPlainArrayToTypoScriptArray(array $plainArray) {
78 $typoScriptArray = array();
79 foreach ($plainArray as $key => $value) {
80 if (is_array($value)) {
81 if (isset($value['_typoScriptNodeValue'])) {
82 $typoScriptArray[$key] = $value['_typoScriptNodeValue'];
83 unset($value['_typoScriptNodeValue']);
84 }
85 $typoScriptArray[$key . '.'] = $this->convertPlainArrayToTypoScriptArray($value);
86 } else {
87 $typoScriptArray[$key] = $value;
88 }
89 }
90 return $typoScriptArray;
91 }
92 }
93
94 ?>