[~TASK] Extbase (Utility): Changed Tx_Extbase_Utility_TypoScript:convertPlainArrayToT...
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Utility / TypoScript.php
index 79771e3..0224b56 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2009 Christian Mller <christian@kitsunet.de>
+*  (c) 2009 Christian Müller <christian@kitsunet.de>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  * @package Extbase
  * @subpackage Utility
  * @version $ID:$
+ * @api
  */
 class Tx_Extbase_Utility_TypoScript {
 
        /**
+        * Removes all trailing dots recursively from TS settings array
+        *
+        * Extbase converts the "classical" TypoScript (with trailing dot) to a format without trailing dot,
+        * to be more future-proof and not to have any conflicts with Fluid object accessor syntax.
+        *
+        * @param array $settings The settings array
+        * @return void
+        * @api
+        */
+       static public function convertTypoScriptArrayToPlainArray(array $settings) {
+               foreach ($settings as $key => &$value) {
+                       if(substr($key, -1) === '.') {
+                               $keyWithoutDot = substr($key, 0, -1);
+                               $hasNodeWithoutDot = array_key_exists($keyWithoutDot, $settings);
+                               $typoScriptNodeValue = $hasNodeWithoutDot ? $settings[$keyWithoutDot] : NULL;
+                               if(is_array($value)) {
+                                       $settings[$keyWithoutDot] = self::convertTypoScriptArrayToPlainArray($value);
+                                       if(!is_null($typoScriptNodeValue)) {
+                                               $settings[$keyWithoutDot]['_typoScriptNodeValue']  = $typoScriptNodeValue;
+                                       }
+                                       unset($settings[$key]);
+                               } else {
+                                       $settings[$keyWithoutDot] = NULL;
+                               }
+                       }
+               }
+               return $settings;
+       }
+
+       /**
         * Returns an array with Typoscript the old way (with dot).
         *
         * Extbase converts the "classical" TypoScript (with trailing dot) to a format without trailing dot,
@@ -39,26 +70,26 @@ class Tx_Extbase_Utility_TypoScript {
         * However, if you want to call legacy TypoScript objects, you somehow need the "old" syntax (because this is what TYPO3 is used to).
         * With this method, you can convert the extbase TypoScript to classical TYPO3 TypoScript which is understood by the rest of TYPO3.
         *
-        * @param array $extbaseTS An Typoscript Array with Extbase Syntax (without dot but with _typoscriptNodeValue)
+        * @param array $plainArray An Typoscript Array with Extbase Syntax (without dot but with _typoScriptNodeValue)
         * @return array array with Typoscript as usual (with dot)
         * @api
         */
-       static public function convertExtbaseToClassicTS($extbaseTS) {
-               $classicTS = array();
-               if (is_array($extbaseTS)) {
-                       foreach ($extbaseTS as $key => $value) {
+       static public function convertPlainArrayToTypoScriptArray($plainArray) {
+               $typoScriptArray = array();
+               if (is_array($plainArray)) {
+                       foreach ($plainArray as $key => $value) {
                                if (is_array($value)) {
-                                       if (isset($value['_typoscriptNodeValue'])) {
-                                               $classicTS[$key] = $value['_typoscriptNodeValue'];
-                                               unset($value['_typoscriptNodeValue']);
+                                       if (isset($value['_typoScriptNodeValue'])) {
+                                               $typoScriptArray[$key] = $value['_typoScriptNodeValue'];
+                                               unset($value['_typoScriptNodeValue']);
                                        }
-                                       $classicTS[$key.'.'] = Tx_Extbase_Utility_TypoScript::convertExtbaseToClassicTS($value);
+                                       $typoScriptArray[$key.'.'] = self::convertPlainArrayToTypoScriptArray($value);
                                } else {
-                                       $classicTS[$key] = $value;
+                                       $typoScriptArray[$key] = $value;
                                }
                        }
                }
-               return $classicTS;
+               return $typoScriptArray;
        }
 }
 ?>
\ No newline at end of file