‪TYPO3CMS  10.4
RequireJsController.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;
25 
30 {
34  protected ‪$pageRenderer;
35 
36  public function ‪__construct()
37  {
38  $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
39  }
40 
66  public function ‪retrieveConfiguration(ServerRequestInterface $request): ResponseInterface
67  {
68  $name = $request->getQueryParams()['name'] ?? null;
69  if (empty($name) || !is_string($name)) {
70  return new ‪JsonResponse(null, 404);
71  }
72  $configuration = $this->‪findConfiguration($name);
73  return new JsonResponse($configuration, !empty($configuration) ? 200 : 404);
74  }
75 
80  protected function ‪findConfiguration(string $name): array
81  {
82  $relevantConfiguration = [];
83  $this->pageRenderer->loadRequireJs();
84  $configuration = $this->pageRenderer->getRequireJsConfig(‪PageRenderer::REQUIREJS_SCOPE_RESOLVE);
85 
86  $shim = $configuration['shim'] ?? [];
87  foreach ($shim as $baseModuleName => $baseModuleConfiguration) {
88  if (strpos($name . '/', $baseModuleName . '/') === 0) {
89  $relevantConfiguration['shim'][$baseModuleName] = $baseModuleConfiguration;
90  }
91  }
92 
93  $paths = $configuration['paths'] ?? [];
94  foreach ($paths as $baseModuleName => $baseModulePath) {
95  if (strpos($name . '/', $baseModuleName . '/') === 0) {
96  $relevantConfiguration['paths'][$baseModuleName] = $baseModulePath;
97  }
98  }
99 
100  $packages = $configuration['packages'] ?? [];
101  foreach ($packages as $package) {
102  if (!empty($package['name'])
103  && strpos($name . '/', $package['name'] . '/') === 0
104  ) {
105  $relevantConfiguration['packages'][] = $package;
106  }
107  }
108 
109  return $relevantConfiguration;
110  }
111 }
‪TYPO3\CMS\Core\Controller\RequireJsController
Definition: RequireJsController.php:30
‪TYPO3\CMS\Core\Controller\RequireJsController\$pageRenderer
‪PageRenderer $pageRenderer
Definition: RequireJsController.php:33
‪TYPO3\CMS\Core\Controller
Definition: ErrorPageController.php:18
‪TYPO3\CMS\Core\Controller\RequireJsController\retrieveConfiguration
‪ResponseInterface retrieveConfiguration(ServerRequestInterface $request)
Definition: RequireJsController.php:65
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:42
‪TYPO3\CMS\Core\Page\PageRenderer\REQUIREJS_SCOPE_RESOLVE
‪const REQUIREJS_SCOPE_RESOLVE
Definition: PageRenderer.php:49
‪TYPO3\CMS\Core\Controller\RequireJsController\findConfiguration
‪array findConfiguration(string $name)
Definition: RequireJsController.php:79
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:26
‪TYPO3\CMS\Core\Controller\RequireJsController\__construct
‪__construct()
Definition: RequireJsController.php:35
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46