‪TYPO3CMS  9.5
RequireJsController.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
23 
28 {
32  protected ‪$pageRenderer;
33 
34  public function ‪__construct()
35  {
36  $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
37  }
38 
64  public function ‪retrieveConfiguration(ServerRequestInterface $request): ResponseInterface
65  {
66  $name = $request->getQueryParams()['name'] ?? null;
67  if (empty($name) || !is_string($name)) {
68  return new ‪JsonResponse(null, 404);
69  }
70  $configuration = $this->‪findConfiguration($name);
71  return new JsonResponse($configuration, !empty($configuration) ? 200 : 404);
72  }
73 
78  protected function ‪findConfiguration(string $name): array
79  {
80  $relevantConfiguration = [];
81  $this->pageRenderer->loadRequireJs();
82  $configuration = $this->pageRenderer->getRequireJsConfig(‪PageRenderer::REQUIREJS_SCOPE_RESOLVE);
83 
84  $shim = $configuration['shim'] ?? [];
85  foreach ($shim as $baseModuleName => $baseModuleConfiguration) {
86  if (strpos($name . '/', $baseModuleName . '/') === 0) {
87  $relevantConfiguration['shim'][$baseModuleName] = $baseModuleConfiguration;
88  }
89  }
90 
91  $paths = $configuration['paths'] ?? [];
92  foreach ($paths as $baseModuleName => $baseModulePath) {
93  if (strpos($name . '/', $baseModuleName . '/') === 0) {
94  $relevantConfiguration['paths'][$baseModuleName] = $baseModulePath;
95  }
96  }
97 
98  $packages = $configuration['packages'] ?? [];
99  foreach ($packages as $package) {
100  if (!empty($package['name'])
101  && strpos($name . '/', $package['name'] . '/') === 0
102  ) {
103  $relevantConfiguration['packages'][] = $package;
104  }
105  }
106 
107  return $relevantConfiguration;
108  }
109 }
‪TYPO3\CMS\Core\Controller\RequireJsController
Definition: RequireJsController.php:28
‪TYPO3\CMS\Core\Controller\RequireJsController\$pageRenderer
‪PageRenderer $pageRenderer
Definition: RequireJsController.php:31
‪TYPO3\CMS\Core\Controller
Definition: ErrorPageController.php:3
‪TYPO3\CMS\Core\Controller\RequireJsController\retrieveConfiguration
‪ResponseInterface retrieveConfiguration(ServerRequestInterface $request)
Definition: RequireJsController.php:63
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:35
‪TYPO3\CMS\Core\Page\PageRenderer\REQUIREJS_SCOPE_RESOLVE
‪const REQUIREJS_SCOPE_RESOLVE
Definition: PageRenderer.php:48
‪TYPO3\CMS\Core\Controller\RequireJsController\findConfiguration
‪array findConfiguration(string $name)
Definition: RequireJsController.php:77
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:25
‪TYPO3\CMS\Core\Controller\RequireJsController\__construct
‪__construct()
Definition: RequireJsController.php:33
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45