‪TYPO3CMS  10.4
RequestHandlersConfigurationFactory.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 
26 use TYPO3\CMS\Core\Package\PackageManager;
30 
35 {
39  private ‪$cacheFrontend;
40 
44  public function ‪__construct(‪CacheManager $cacheManager = null)
45  {
46  $cacheIdentifier = 'extbase';
47 
48  ‪$cacheFrontend = new ‪NullFrontend($cacheIdentifier);
49  if ($cacheManager !== null) {
50  try {
51  ‪$cacheFrontend = $cacheManager->getCache($cacheIdentifier);
52  } catch (‪NoSuchCacheException $e) {
53  // Handling this exception is not needed as $cacheFrontend is
54  // a NullFrontend at this moment.
55  }
56  }
57 
58  $this->cacheFrontend = ‪$cacheFrontend;
59  }
60 
66  {
67  $cacheEntryIdentifier = 'RequestHandlers_' . sha1((string)(new ‪Typo3Version()) . ‪Environment::getProjectPath());
68 
69  $requestHandlersCache = $this->cacheFrontend->get($cacheEntryIdentifier);
70  if ($requestHandlersCache) {
71  return new ‪RequestHandlersConfiguration($requestHandlersCache);
72  }
73 
74  $classes = [];
75  foreach (GeneralUtility::makeInstance(PackageManager::class)->getActivePackages() as $activePackage) {
76  $requestHandlersFile = $activePackage->getPackagePath() . 'Configuration/Extbase/RequestHandlers.php';
77  if (file_exists($requestHandlersFile)) {
78  $definedClasses = require $requestHandlersFile;
79  if (!is_array($definedClasses)) {
80  continue;
81  }
82 
83  foreach ($definedClasses as $definedClass) {
84  if (!class_exists($definedClass)) {
85  throw new ‪Exception(
86  sprintf(
87  'Request class "%s", registered in "%s", does not exist.',
88  $definedClass,
89  $requestHandlersFile
90  ),
91  1562253559
92  );
93  }
94 
95  if (!in_array(RequestHandlerInterface::class, class_implements($definedClass), true)) {
96  throw new ‪Exception(
97  sprintf(
98  'Request class "%s", registered in "%s", does not implement interface "%s".',
99  $definedClass,
100  $requestHandlersFile,
101  RequestHandlerInterface::class
102  ),
103  1562257073
104  );
105  }
106 
107  $classes[] = $definedClass;
108  }
109  }
110  }
111 
112  $this->cacheFrontend->set($cacheEntryIdentifier, $classes);
113 
114  return new ‪RequestHandlersConfiguration($classes);
115  }
116 }
‪TYPO3\CMS\Core\Information\Typo3Version
Definition: Typo3Version.php:21
‪TYPO3\CMS\Extbase\Configuration\RequestHandlersConfigurationFactory
Definition: RequestHandlersConfigurationFactory.php:35
‪TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
Definition: NoSuchCacheException.php:24
‪TYPO3\CMS\Core\Cache\Frontend\NullFrontend
Definition: NullFrontend.php:29
‪TYPO3\CMS\Extbase\Configuration\RequestHandlersConfigurationFactory\__construct
‪__construct(CacheManager $cacheManager=null)
Definition: RequestHandlersConfigurationFactory.php:43
‪TYPO3\CMS\Core\Core\Environment\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:169
‪TYPO3\CMS\Extbase\Configuration\RequestHandlersConfigurationFactory\$cacheFrontend
‪FrontendInterface $cacheFrontend
Definition: RequestHandlersConfigurationFactory.php:38
‪TYPO3\CMS\Extbase\Configuration\Exception
Definition: Exception.php:26
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Extbase\Mvc\RequestHandlerInterface
Definition: RequestHandlerInterface.php:22
‪TYPO3\CMS\Extbase\Configuration\RequestHandlersConfiguration
Definition: RequestHandlersConfiguration.php:24
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extbase\Configuration
Definition: AbstractConfigurationManager.php:18
‪TYPO3\CMS\Extbase\Configuration\RequestHandlersConfigurationFactory\createRequestHandlersConfiguration
‪RequestHandlersConfiguration createRequestHandlersConfiguration()
Definition: RequestHandlersConfigurationFactory.php:64