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