TYPO3 CMS  TYPO3_7-6
AbstractGenerator.php
Go to the documentation of this file.
1 <?php
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 = [];
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  // Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept
109  $previousValueOfEntityLoader = libxml_disable_entity_loader(true);
110  $parentDomNode = dom_import_simplexml($parentXmlNode);
111  $domDocument = new \DOMDocument();
112 
113  $childNode = $domDocument->appendChild($domDocument->createElement($childNodeName));
114  $childNode->appendChild($domDocument->createCDATASection($childNodeValue));
115  $childNodeTarget = $parentDomNode->ownerDocument->importNode($childNode, true);
116  $parentDomNode->appendChild($childNodeTarget);
117  $returnValue = simplexml_import_dom($childNodeTarget);
118  libxml_disable_entity_loader($previousValueOfEntityLoader);
119 
120  return $returnValue;
121  }
122 }
addChildWithCData(\SimpleXMLElement $parentXmlNode, $childNodeName, $childNodeValue)
const NAMESPACE_SEPARATOR
Definition: Fluid.php:19