Extbase:
authorSebastian Kurfürst <sebastian@typo3.org>
Thu, 2 Jul 2009 20:58:23 +0000 (20:58 +0000)
committerSebastian Kurfürst <sebastian@typo3.org>
Thu, 2 Jul 2009 20:58:23 +0000 (20:58 +0000)
[+FEAT]: Added TypoScript converter method (to convert from new TS to classic TS). Fixes #3293.

typo3/sysext/extbase/Classes/Utility/TypoScript.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Utility/TypoScript_testcase.php [new file with mode: 0644]

diff --git a/typo3/sysext/extbase/Classes/Utility/TypoScript.php b/typo3/sysext/extbase/Classes/Utility/TypoScript.php
new file mode 100644 (file)
index 0000000..195ca99
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Christian Müller <christian@kitsunet.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!
+***************************************************************/
+
+/**
+ * Utilities to manage and convert Typoscript Code
+ *
+ * @package Extbase
+ * @subpackage extbase
+ * @version $ID:$
+ */
+class Tx_Extbase_Utility_TypoScript {
+
+       /**
+        * Returns an array with Typoscript the old way (with dot).
+        * 
+        * 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.
+        * 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)
+        * @return array array with Typoscript as usual (with dot)
+        */
+       static public function convertExtbaseToClassicTS($extbaseTS) {
+               $classicTS = array();
+               if (is_array($extbaseTS)) {
+                       foreach ($extbaseTS as $key => $value) {
+                               if (is_array($value)) {
+                                       if (isset($value['_typoscriptNodeValue'])) {
+                                               $classicTS[$key] = $value['_typoscriptNodeValue'];
+                                               unset($value['_typoscriptNodeValue']);
+                                       }
+                                       $classicTS[$key.'.'] = Tx_Extbase_Utility_TypoScript::convertExtbaseToClassicTS($value);
+                               } else {
+                                       $classicTS[$key] = $value;
+                               }
+                       }
+               }
+               return $classicTS;
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Utility/TypoScript_testcase.php b/typo3/sysext/extbase/Tests/Utility/TypoScript_testcase.php
new file mode 100644 (file)
index 0000000..c0060f4
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Christian Müller <christian@kitsunet.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!
+***************************************************************/
+
+
+/**
+ * Testcase for class Tx_Extbase_Utility_TypoScript
+ *
+ * @package Extbase
+ * @subpackage extbase
+ */
+
+class Tx_Extbase_Utility_TypoScript_testcase extends tx_phpunit_testcase {
+
+       /**
+        * @test
+        * @see Tx_Extbase_Utility_TypoScript::convertExtbaseToClassicTS
+        */
+       public function basicExtBase2ClassicTest() {
+               $extbaseTS = array(
+                       '10' => array(
+                               'value' => 'Hallo',
+                               '_typoscriptNodeValue' => 'TEXT'
+                       )
+               );
+
+               $classic = array(
+                       '10' => 'TEXT',
+                       '10.' => array(
+                               'value' => 'Hallo'
+                       )
+               );
+
+               $converted = Tx_Extbase_Utility_TypoScript::convertExtbaseToClassicTS($extbaseTS);
+
+               $this->assertEquals($converted, $classic);
+       }
+}
+?>
\ No newline at end of file