‪TYPO3CMS  ‪main
ModuleLoader.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 
25 
32 {
40  public function validateSortAndInitializeModules(array $modules): array
41  {
42  if (empty($modules)) {
43  return [];
44  }
45  foreach ($modules as ‪$identifier => $configuration) {
46  if (empty($configuration) || !is_array($configuration)) {
47  throw new \RuntimeException(
48  'Missing configuration for module "' . ‪$identifier . '".',
49  1519490105
50  );
51  }
52  if (empty($configuration['module']) ||
53  !is_string($configuration['module']) ||
54  !class_exists($configuration['module']) ||
55  !is_subclass_of(
56  $configuration['module'],
57  ModuleInterface::class,
58  true
59  )
60  ) {
61  throw new \RuntimeException(
62  'The module "' .
64  '" defines an invalid module class. Ensure the class exists and implements the "' .
65  ModuleInterface::class .
66  '".',
67  1519490112
68  );
69  }
70  }
71 
72  $orderedModules = GeneralUtility::makeInstance(DependencyOrderingService::class)->orderByDependencies(
73  $modules
74  );
75 
77  foreach ($orderedModules as $moduleConfiguration) {
78  $module = GeneralUtility::makeInstance($moduleConfiguration['module']);
79  if (
80  $module instanceof ‪ModuleInterface
81  && (
82  ($module instanceof ‪ConfigurableInterface && $module->‪isEnabled())
83  || !($module instanceof ‪ConfigurableInterface)
84  )
85  ) {
86  ‪$moduleInstances[$module->getIdentifier()] = $module;
87  }
88  if ($module instanceof ‪SubmoduleProviderInterface) {
89  $subModuleInstances = $this->validateSortAndInitializeModules($moduleConfiguration['submodules'] ?? []);
90  $module->setSubModules($subModuleInstances);
91  }
92  }
94  }
95 }
‪TYPO3\CMS\Adminpanel\Service\ModuleLoader
Definition: ModuleLoader.php:32
‪TYPO3\CMS\Adminpanel\ModuleApi\ConfigurableInterface
Definition: ConfigurableInterface.php:29
‪TYPO3\CMS\Adminpanel\ModuleApi\ConfigurableInterface\isEnabled
‪isEnabled()
‪TYPO3\CMS\Adminpanel\Service\ModuleLoader\$moduleInstances
‪$moduleInstances
Definition: ModuleLoader.php:76
‪TYPO3\CMS\Adminpanel\Service
Definition: ConfigurationService.php:18
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:32
‪TYPO3\CMS\Adminpanel\ModuleApi\ModuleInterface
Definition: ModuleInterface.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Adminpanel\ModuleApi\SubmoduleProviderInterface
Definition: SubmoduleProviderInterface.php:30
‪TYPO3\CMS\Adminpanel\Service\ModuleLoader\$moduleInstances
‪foreach($orderedModules as $moduleConfiguration) return $moduleInstances
Definition: ModuleLoader.php:77
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37