‪TYPO3CMS  11.5
TypoScriptReferenceController.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
22 
28 {
32  protected ‪$xmlDoc;
33 
40  public function ‪loadReference(ServerRequestInterface $request): ResponseInterface
41  {
42  // Load the TSref XML information:
43  $this->‪loadFile(GeneralUtility::getFileAbsFileName('EXT:t3editor/Resources/Private/tsref.xml'));
44  return new ‪JsonResponse($this->‪getTypes());
45  }
46 
52  protected function ‪loadFile($filepath)
53  {
54  // Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept
55  $previousValueOfEntityLoader = null;
56  if (PHP_MAJOR_VERSION < 8) {
57  $previousValueOfEntityLoader = libxml_disable_entity_loader();
58  }
59  $this->xmlDoc = new \DOMDocument('1.0', 'utf-8');
60  $this->xmlDoc->loadXML(file_get_contents($filepath));
61  if (PHP_MAJOR_VERSION < 8) {
62  libxml_disable_entity_loader($previousValueOfEntityLoader);
63  }
64  // @TODO: oliver@typo3.org: I guess this is not required here
65  $this->xmlDoc->saveXML();
66  }
67 
73  protected function ‪getTypes(): array
74  {
75  $types = $this->xmlDoc->getElementsByTagName('type');
76  $typeArr = [];
77  foreach ($types as $type) {
78  $typeId = $type->getAttribute('id');
79  $typeName = $type->getAttribute('name');
80  if (!$typeName) {
81  $typeName = $typeId;
82  }
83  $properties = $type->getElementsByTagName('property');
84  $propArr = [];
85  foreach ($properties as $property) {
86  $p = [];
87  $p['name'] = $property->getAttribute('name');
88  $p['type'] = $property->getAttribute('type');
89  $propArr[$property->getAttribute('name')] = $p;
90  }
91  $typeArr[$typeId] = [];
92  $typeArr[$typeId]['properties'] = $propArr;
93  $typeArr[$typeId]['name'] = $typeName;
94  if ($type->hasAttribute('extends')) {
95  $typeArr[$typeId]['extends'] = $type->getAttribute('extends');
96  }
97  }
98  return $typeArr;
99  }
100 }
‪TYPO3\CMS\T3editor\Controller\TypoScriptReferenceController
Definition: TypoScriptReferenceController.php:28
‪TYPO3\CMS\T3editor\Controller\TypoScriptReferenceController\loadReference
‪ResponseInterface loadReference(ServerRequestInterface $request)
Definition: TypoScriptReferenceController.php:39
‪TYPO3\CMS\T3editor\Controller\TypoScriptReferenceController\loadFile
‪loadFile($filepath)
Definition: TypoScriptReferenceController.php:51
‪TYPO3\CMS\T3editor\Controller\TypoScriptReferenceController\getTypes
‪array getTypes()
Definition: TypoScriptReferenceController.php:72
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:28
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\T3editor\Controller\TypoScriptReferenceController\$xmlDoc
‪DOMDocument $xmlDoc
Definition: TypoScriptReferenceController.php:31
‪TYPO3\CMS\T3editor\Controller
Definition: CodeCompletionController.php:16