[~TASK] Extbase (Utility): Changed Tx_Extbase_Utility_TypoScript:convertPlainArrayToT...
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Utility / TypoScript.php
index 098e2fc..0224b56 100644 (file)
  * @package Extbase
  * @subpackage Utility
  * @version $ID:$
+ * @api
  */
 class Tx_Extbase_Utility_TypoScript {
 
        /**
         * Removes all trailing dots recursively from TS settings array
-        * TODO Explain why we remove the dots.
         *
-        * @param array $setup The 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
         */
-       public static function convertTypoScriptArrayToPlainArray(array $settings) {
-               $processedSettings = array();
-               // TODO Check if the t3lib_div::removeDotsFromTS() fits for this purpose (using rtrim() for removing trailing dots)
-               foreach ($settings as $key => $value) {
-                       if (substr($key, -1) === '.') {
+       static public function convertTypoScriptArrayToPlainArray(array $settings) {
+               foreach ($settings as $key => &$value) {
+                       if(substr($key, -1) === '.') {
                                $keyWithoutDot = substr($key, 0, -1);
-                               if (is_array($value)) {
-                                       $processedSettings[$keyWithoutDot] = self::convertTypoScriptArrayToPlainArray($value);
-                               } else {
-                                       $processedSettings[$keyWithoutDot] = NULL;
-                               }
-                               if (array_key_exists($keyWithoutDot, $settings)) {
-                                       $processedSettings[$keyWithoutDot]['_typoScriptNodeValue'] = $settings[$keyWithoutDot];
-                                       unset($settings[$keyWithoutDot]);
-                               }
-                       } else {
-                               $keyWithDot = $key . '.';
-                               if (array_key_exists($keyWithDot, $settings)) {
-                                       $processedSettings[$key] = self::convertTypoScriptArrayToPlainArray($settings[$keyWithDot]);
-                                       $processedSettings[$key]['_typoScriptNodeValue'] = $value;
-                                       unset($settings[$keyWithDot]);
+                               $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 {
-                                       $processedSettings[$key] = $value;
+                                       $settings[$keyWithoutDot] = NULL;
                                }
                        }
                }
-               return $processedSettings;
+               return $settings;
        }
 
        /**
@@ -80,7 +74,7 @@ class Tx_Extbase_Utility_TypoScript {
         * @return array array with Typoscript as usual (with dot)
         * @api
         */
-       public static function convertPlainArrayToTypoScriptArray($plainArray) {
+       static public function convertPlainArrayToTypoScriptArray($plainArray) {
                $typoScriptArray = array();
                if (is_array($plainArray)) {
                        foreach ($plainArray as $key => $value) {
@@ -89,7 +83,7 @@ class Tx_Extbase_Utility_TypoScript {
                                                $typoScriptArray[$key] = $value['_typoScriptNodeValue'];
                                                unset($value['_typoScriptNodeValue']);
                                        }
-                                       $typoScriptArray[$key.'.'] = Tx_Extbase_Utility_TypoScript::convertPlainArrayToTypoScriptArray($value);
+                                       $typoScriptArray[$key.'.'] = self::convertPlainArrayToTypoScriptArray($value);
                                } else {
                                        $typoScriptArray[$key] = $value;
                                }