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