[BUGFIX] Abstract XSD generator can handle more than two namespace parts 71/42971/3
authorHelmut Hummel <helmut.hummel@typo3.org>
Tue, 1 Sep 2015 20:10:56 +0000 (22:10 +0200)
committerNicole Cordes <typo3@cordes.co>
Wed, 2 Sep 2015 07:41:16 +0000 (09:41 +0200)
The getTagNameForClass method in the abstract XSD generator class
could not handle class names with more than two namespace parts.

This caused e.g. TYPO3\CMS\Fluid\ViewHelpers\Be\Buttons\CshViewHelper to
not be transformed to "be.buttons.csh", but just "be.", which in turn
caused duplicate id errors in the resulting XSD document.

Make the code aware of more than two namespace parts.

Releases: master, 6.2
Resolves: #69463
Change-Id: I9a6a28b470679e7487f0d83a7ce9f267a1f3ec7f
Reviewed-on: http://review.typo3.org/42971
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
typo3/sysext/fluid/Classes/Service/AbstractGenerator.php

index 78270ce..6e3c5f3 100644 (file)
@@ -78,15 +78,18 @@ abstract class AbstractGenerator {
         * @return string Tag name
         */
        protected function getTagNameForClass($className, $namespace) {
-               $strippedClassName = substr($className, strlen($namespace));
+               /// Strip namespace from the beginning and "ViewHelper" from the end of the class name
+               $strippedClassName = substr($className, strlen($namespace), -10);
                $classNameParts = explode(\TYPO3\CMS\Fluid\Fluid::NAMESPACE_SEPARATOR, $strippedClassName);
-
-               if (count($classNameParts) == 1) {
-                       $tagName = lcfirst(substr($classNameParts[0], 0, -10)); // strip the "ViewHelper" ending
-               } else {
-                       $tagName = lcfirst($classNameParts[0]) . '.' . lcfirst(substr($classNameParts[1], 0, -10));
-               }
-               return $tagName;
+               return implode(
+                       '.',
+                       array_map(
+                               function($element) {
+                                       return lcfirst($element);
+                               },
+                               $classNameParts
+                       )
+               );
        }
 
        /**