|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009 Christian Müller <christian@kitsunet.de> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 /** 00026 * Utilities to manage and convert Typoscript Code 00027 * 00028 * @package Extbase 00029 * @subpackage Utility 00030 * @version $ID:$ 00031 * @api 00032 */ 00033 class Tx_Extbase_Utility_TypoScript { 00034 00035 /** 00036 * Removes all trailing dots recursively from TS settings array 00037 * 00038 * Extbase converts the "classical" TypoScript (with trailing dot) to a format without trailing dot, 00039 * to be more future-proof and not to have any conflicts with Fluid object accessor syntax. 00040 * 00041 * @param array $settings The settings array 00042 * @return void 00043 * @api 00044 */ 00045 static public function convertTypoScriptArrayToPlainArray(array $settings) { 00046 foreach ($settings as $key => &$value) { 00047 if(substr($key, -1) === '.') { 00048 $keyWithoutDot = substr($key, 0, -1); 00049 $hasNodeWithoutDot = array_key_exists($keyWithoutDot, $settings); 00050 $typoScriptNodeValue = $hasNodeWithoutDot ? $settings[$keyWithoutDot] : NULL; 00051 if(is_array($value)) { 00052 $settings[$keyWithoutDot] = self::convertTypoScriptArrayToPlainArray($value); 00053 if(!is_null($typoScriptNodeValue)) { 00054 $settings[$keyWithoutDot]['_typoScriptNodeValue'] = $typoScriptNodeValue; 00055 } 00056 unset($settings[$key]); 00057 } else { 00058 $settings[$keyWithoutDot] = NULL; 00059 } 00060 } 00061 } 00062 return $settings; 00063 } 00064 00065 /** 00066 * Returns an array with Typoscript the old way (with dot). 00067 * 00068 * Extbase converts the "classical" TypoScript (with trailing dot) to a format without trailing dot, 00069 * to be more future-proof and not to have any conflicts with Fluid object accessor syntax. 00070 * However, if you want to call legacy TypoScript objects, you somehow need the "old" syntax (because this is what TYPO3 is used to). 00071 * With this method, you can convert the extbase TypoScript to classical TYPO3 TypoScript which is understood by the rest of TYPO3. 00072 * 00073 * @param array $plainArray An Typoscript Array with Extbase Syntax (without dot but with _typoScriptNodeValue) 00074 * @return array array with Typoscript as usual (with dot) 00075 * @api 00076 */ 00077 static public function convertPlainArrayToTypoScriptArray($plainArray) { 00078 $typoScriptArray = array(); 00079 if (is_array($plainArray)) { 00080 foreach ($plainArray as $key => $value) { 00081 if (is_array($value)) { 00082 if (isset($value['_typoScriptNodeValue'])) { 00083 $typoScriptArray[$key] = $value['_typoScriptNodeValue']; 00084 unset($value['_typoScriptNodeValue']); 00085 } 00086 $typoScriptArray[$key.'.'] = self::convertPlainArrayToTypoScriptArray($value); 00087 } else { 00088 $typoScriptArray[$key] = $value; 00089 } 00090 } 00091 } 00092 return $typoScriptArray; 00093 } 00094 } 00095 ?>
1.8.0