‪TYPO3CMS  10.4
LateBootService.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\Container\ContainerInterface;
21 use Psr\EventDispatcher\EventDispatcherInterface;
23 use TYPO3\CMS\Core\DependencyInjection\ContainerBuilder;
25 use TYPO3\CMS\Core\Package\PackageManager;
29 
34 {
38  private ‪$containerBuilder;
39 
43  private ‪$failsafeContainer;
44 
48  private ‪$container;
49 
54  public function ‪__construct(ContainerBuilder ‪$containerBuilder, ContainerInterface ‪$failsafeContainer)
55  {
56  $this->containerBuilder = ‪$containerBuilder;
57  $this->failsafeContainer = ‪$failsafeContainer;
58  }
59 
63  public function ‪getContainer(): ContainerInterface
64  {
65  return $this->container ?? $this->‪prepareContainer();
66  }
67 
71  private function ‪prepareContainer(): ContainerInterface
72  {
73  $packageManager = $this->failsafeContainer->get(PackageManager::class);
74  $dependencyInjectionContainerCache = $this->failsafeContainer->get('cache.di');
75 
76  $failsafe = false;
77 
78  // Build a non-failsafe container which is required for loading ext_localconf
79  return $this->container = $this->containerBuilder->createDependencyInjectionContainer($packageManager, $dependencyInjectionContainerCache, $failsafe);
80  }
81 
91  public function ‪makeCurrent(ContainerInterface ‪$container = null, array $backup = []): array
92  {
93  ‪$container = ‪$container ?? $backup['container'] ?? ‪$this->failsafeContainer;
94 
95  $newBackup = [
96  'singletonInstances' => GeneralUtility::getSingletonInstances(),
97  'container' => GeneralUtility::getContainer(),
98  ];
99 
100  GeneralUtility::purgeInstances();
101 
102  // Set global state to the non-failsafe container and it's instances
103  GeneralUtility::setContainer(‪$container);
105 
106  $backupSingletonInstances = $backup['singletonInstances'] ?? [];
107  foreach ($backupSingletonInstances as $className => $instance) {
108  GeneralUtility::setSingletonInstance($className, $instance);
109  }
110 
111  return $newBackup;
112  }
113 
126  public function ‪loadExtLocalconfDatabaseAndExtTables(bool $resetContainer = true): ContainerInterface
127  {
128  ‪$container = $this->‪getContainer();
129 
130  $backup = $this->‪makeCurrent(‪$container);
131 
132  ‪$container->get('boot.state')->done = false;
133  $assetsCache = ‪$container->get('cache.assets');
134  ‪IconRegistry::setCache($assetsCache);
135  ‪PageRenderer::setCache($assetsCache);
136  $eventDispatcher = ‪$container->get(EventDispatcherInterface::class);
140  ‪$container->get('boot.state')->done = true;
143 
144  if ($resetContainer) {
145  $this->‪makeCurrent(null, $backup);
146  }
147 
149  }
150 
151  public function ‪resetGlobalContainer(): void
152  {
153  $this->‪makeCurrent(null, []);
154  }
155 }
‪TYPO3\CMS\Core\Core\Bootstrap\loadTypo3LoadedExtAndExtLocalconf
‪static loadTypo3LoadedExtAndExtLocalconf($allowCaching=true, FrontendInterface $coreCache=null)
Definition: Bootstrap.php:278
‪TYPO3\CMS\Core\Core\Bootstrap\unsetReservedGlobalVariables
‪static unsetReservedGlobalVariables()
Definition: Bootstrap.php:494
‪TYPO3\CMS\Install\Service\LateBootService\$failsafeContainer
‪ContainerInterface $failsafeContainer
Definition: LateBootService.php:41
‪TYPO3\CMS\Install\Service\LateBootService\$containerBuilder
‪ContainerBuilder $containerBuilder
Definition: LateBootService.php:37
‪TYPO3\CMS\Install\Service\LateBootService\__construct
‪__construct(ContainerBuilder $containerBuilder, ContainerInterface $failsafeContainer)
Definition: LateBootService.php:51
‪TYPO3\CMS\Install\Service\LateBootService\prepareContainer
‪ContainerInterface prepareContainer()
Definition: LateBootService.php:68
‪TYPO3\CMS\Core\Core\Bootstrap\loadBaseTca
‪static loadBaseTca(bool $allowCaching=true, FrontendInterface $coreCache=null)
Definition: Bootstrap.php:516
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:42
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\setPackageManager
‪static setPackageManager(PackageManager $packageManager)
Definition: ExtensionManagementUtility.php:66
‪TYPO3\CMS\Install\Service\LateBootService\loadExtLocalconfDatabaseAndExtTables
‪ContainerInterface loadExtLocalconfDatabaseAndExtTables(bool $resetContainer=true)
Definition: LateBootService.php:123
‪TYPO3\CMS\Core\Imaging\IconRegistry
Definition: IconRegistry.php:38
‪TYPO3\CMS\Core\Page\PageRenderer\setCache
‪static setCache(FrontendInterface $cache)
Definition: PageRenderer.php:350
‪TYPO3\CMS\Install\Service\LateBootService\resetGlobalContainer
‪resetGlobalContainer()
Definition: LateBootService.php:148
‪TYPO3\CMS\Install\Service\LateBootService
Definition: LateBootService.php:34
‪TYPO3\CMS\Install\Service\LateBootService\$container
‪ContainerInterface $container
Definition: LateBootService.php:45
‪TYPO3\CMS\Install\Service\LateBootService\getContainer
‪ContainerInterface getContainer()
Definition: LateBootService.php:60
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:66
‪TYPO3\CMS\Core\Core\Bootstrap\loadExtTables
‪static loadExtTables(bool $allowCaching=true)
Definition: Bootstrap.php:546
‪TYPO3\CMS\Install\Service\LateBootService\makeCurrent
‪array makeCurrent(ContainerInterface $container=null, array $backup=[])
Definition: LateBootService.php:88
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\setEventDispatcher
‪static setEventDispatcher(EventDispatcherInterface $eventDispatcher)
Definition: ExtensionManagementUtility.php:81
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Install\Service
Definition: ClearCacheService.php:16
‪TYPO3\CMS\Core\Imaging\IconRegistry\setCache
‪static setCache(FrontendInterface $cache)
Definition: IconRegistry.php:460