Extbase:
authorJochen Rau <j.rau@web.de>
Sat, 16 May 2009 10:48:58 +0000 (10:48 +0000)
committerJochen Rau <j.rau@web.de>
Sat, 16 May 2009 10:48:58 +0000 (10:48 +0000)
* TypoScriptSource: All trailing dots are removed recursively from TypoScript Settings. The node value (like 10 = TEXT) is now stored assigned to a "private" array key called "_typoScriptNodeValue".

typo3/sysext/extbase/Classes/Configuration/Source/TypoScriptSource.php
typo3/sysext/extbase/Tests/Configuration/Source/TypoScriptSource_testcase.php [new file with mode: 0644]

index 9efb3d0..e7b0639 100644 (file)
@@ -55,8 +55,23 @@ class Tx_Extbase_Configuration_Source_TypoScriptSource implements Tx_Extbase_Con
        protected function postProcessSettings(array $settings) {
                $processedSettings = array();
                foreach ($settings as $key => $value) {
-                       if (is_array($value)) $value = $this->postProcessSettings($value);
-                       $processedSettings[preg_replace('/(.*)\.$/', '\1', $key, 1)] = $value;
+                       if (substr($key, -1) === '.') {
+                               $keyWithoutDot = substr($key, 0, -1);
+                               $processedSettings[$keyWithoutDot] = $this->postProcessSettings($value);
+                               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] = $this->postProcessSettings($settings[$keyWithDot]);
+                                       $processedSettings[$key]['_typoScriptNodeValue'] = $value;
+                                       unset($settings[$keyWithDot]);
+                               } else {
+                                       $processedSettings[$key] = $value;
+                               }
+                       }
                }
                return $processedSettings;
        }
diff --git a/typo3/sysext/extbase/Tests/Configuration/Source/TypoScriptSource_testcase.php b/typo3/sysext/extbase/Tests/Configuration/Source/TypoScriptSource_testcase.php
new file mode 100644 (file)
index 0000000..f20b3a3
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+class Tx_Extbase_Configuration_Source_TypoScriptSource_testcase extends Tx_Extbase_Base_testcase {
+       
+       /**
+        * @test
+        */     
+       public function postProcessSettingsRemovesTrailingDots() {              
+               $typoScriptSettings = array(
+                       '10' => 'TEXT',
+                       '10.' => array(
+                               'value' => 'Hello World!',
+                               'foo.' => array(
+                                       'bar' => 5,
+                                       ),
+                               ),
+                       );
+               $expectedSettings = array(
+                       '10' => array(
+                               'value' => 'Hello World!',
+                               'foo' => array(
+                                       'bar' => 5,                                     
+                                       ),
+                               '_typoScriptNodeValue' => 'TEXT',
+                               ),
+                       );
+               $configurationSource = t3lib_div::makeInstance($this->buildAccessibleProxy('Tx_Extbase_Configuration_Source_TypoScriptSource'));
+               $processedSettings = $configurationSource->_callRef('postProcessSettings', $typoScriptSettings);
+
+               $this->assertEquals($expectedSettings, $processedSettings);             
+       }
+       
+       /**
+        * @test
+        */
+       public function postProcessSettingsRemovesTrailingDotsWithChangedOrderInTheTypoScriptArray() {          
+               $typoScriptSettings = array(
+                       '10.' => array(
+                               'value' => 'Hello World!',
+                               'foo.' => array(
+                                       'bar' => 5,
+                                       ),
+                               ),
+                       '10' => 'TEXT', // This line was moved down
+                       );
+               $expectedSettings = array(
+                       '10' => array(
+                               'value' => 'Hello World!',
+                               'foo' => array(
+                                       'bar' => 5,                                     
+                                       ),
+                               '_typoScriptNodeValue' => 'TEXT',
+                               ),
+                       );
+               $configurationSource = t3lib_div::makeInstance($this->buildAccessibleProxy('Tx_Extbase_Configuration_Source_TypoScriptSource'));
+               $processedSettings = $configurationSource->_callRef('postProcessSettings', $typoScriptSettings);
+
+               $this->assertEquals($expectedSettings, $processedSettings);             
+       }
+       
+}
+?>
\ No newline at end of file