TYPO3  7.6
AbstractGenerator.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Fluid\Service;
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
17 abstract class AbstractGenerator
18 {
25 
32  protected $docCommentParser;
33 
38  protected $reflectionService;
39 
44  public function __construct()
45  {
46  \TYPO3\CMS\Fluid\Fluid::$debugMode = true; // We want ViewHelper argument documentation
47  $this->abstractViewHelperReflectionClass = new \TYPO3\CMS\Extbase\Reflection\ClassReflection(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper::class);
48  }
49 
56  protected function getClassNamesInNamespace($namespace)
57  {
58  $affectedViewHelperClassNames = array();
59 
60  $allViewHelperClassNames = $this->reflectionService->getAllSubClassNamesForClass(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper::class);
61  foreach ($allViewHelperClassNames as $viewHelperClassName) {
62  if ($this->reflectionService->isClassAbstract($viewHelperClassName)) {
63  continue;
64  }
65  if (strncmp($namespace, $viewHelperClassName, strlen($namespace)) === 0) {
66  $affectedViewHelperClassNames[] = $viewHelperClassName;
67  }
68  }
69  sort($affectedViewHelperClassNames);
70  return $affectedViewHelperClassNames;
71  }
72 
82  protected function getTagNameForClass($className, $namespace)
83  {
85  $strippedClassName = substr($className, strlen($namespace), -10);
86  $classNameParts = explode(\TYPO3\CMS\Fluid\Fluid::NAMESPACE_SEPARATOR, $strippedClassName);
87  return implode(
88  '.',
89  array_map(
90  function ($element) {
91  return lcfirst($element);
92  },
93  $classNameParts
94  )
95  );
96  }
97 
106  protected function addChildWithCData(\SimpleXMLElement $parentXmlNode, $childNodeName, $childNodeValue)
107  {
108  $parentDomNode = dom_import_simplexml($parentXmlNode);
109  $domDocument = new \DOMDocument();
110 
111  $childNode = $domDocument->appendChild($domDocument->createElement($childNodeName));
112  $childNode->appendChild($domDocument->createCDATASection($childNodeValue));
113  $childNodeTarget = $parentDomNode->ownerDocument->importNode($childNode, true);
114  $parentDomNode->appendChild($childNodeTarget);
115  return simplexml_import_dom($childNodeTarget);
116  }
117 }