‪TYPO3CMS  11.5
BootService.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 
18 namespace ‪TYPO3\CMS\Core\Core;
19 
20 use Psr\Container\ContainerInterface;
21 use Psr\EventDispatcher\EventDispatcherInterface;
23 use TYPO3\CMS\Core\DependencyInjection\ContainerBuilder;
24 use TYPO3\CMS\Core\Package\PackageManager;
25 use TYPO3\CMS\Core\Page\PageRenderer;
28 
33 {
34  private ContainerBuilder ‪$containerBuilder;
35 
36  private ContainerInterface ‪$failsafeContainer;
37 
38  private ?ContainerInterface ‪$container = null;
39 
40  public function ‪__construct(ContainerBuilder ‪$containerBuilder, ContainerInterface ‪$failsafeContainer)
41  {
42  $this->containerBuilder = ‪$containerBuilder;
43  $this->failsafeContainer = ‪$failsafeContainer;
44  }
45 
46  public function ‪getContainer(bool $allowCaching = true): ContainerInterface
47  {
48  return $this->container ?? $this->‪prepareContainer($allowCaching);
49  }
50 
51  private function ‪prepareContainer(bool $allowCaching = true): ContainerInterface
52  {
53  $packageManager = $this->failsafeContainer->get(PackageManager::class);
54  $dependencyInjectionContainerCache = $this->failsafeContainer->get('cache.di');
55 
56  $failsafe = false;
57 
58  // Build a non-failsafe container which is required for loading ext_localconf
59  $this->container = $this->containerBuilder->createDependencyInjectionContainer($packageManager, $dependencyInjectionContainerCache, $failsafe);
60  $this->container->set('_early.boot-service', $this);
61  if ($allowCaching) {
62  $this->container->get('boot.state')->cacheDisabled = false;
63  $coreCache = ‪Bootstrap::createCache('core');
64  // Core cache is initialized with a NullBackend in failsafe mode.
65  // Replace it with a new cache that uses the real backend.
66  $this->container->set('_early.cache.core', $coreCache);
67  $this->container->set('_early.cache.assets', ‪Bootstrap::createCache('assets'));
69  $this->container->get(PackageManager::class)->setPackageCache(‪Bootstrap::createPackageCache($coreCache));
70  }
71  }
72 
73  return ‪$this->container;
74  }
75 
85  public function ‪makeCurrent(ContainerInterface ‪$container = null, array $backup = []): array
86  {
87  ‪$container = ‪$container ?? $backup['container'] ?? ‪$this->failsafeContainer;
88 
89  $newBackup = [
90  'singletonInstances' => GeneralUtility::getSingletonInstances(),
91  'container' => GeneralUtility::getContainer(),
92  ];
93 
94  GeneralUtility::purgeInstances();
95 
96  // Set global state to the non-failsafe container and it's instances
97  GeneralUtility::setContainer(‪$container);
99 
100  $backupSingletonInstances = $backup['singletonInstances'] ?? [];
101  foreach ($backupSingletonInstances as $className => $instance) {
102  GeneralUtility::setSingletonInstance($className, $instance);
103  }
104 
105  return $newBackup;
106  }
107 
121  public function ‪loadExtLocalconfDatabaseAndExtTables(bool $resetContainer = false, bool $allowCaching = true): ContainerInterface
122  {
123  ‪$container = $this->‪getContainer($allowCaching);
124 
125  $backup = $this->‪makeCurrent($container);
126  $beUserBackup = ‪$GLOBALS['BE_USER'] ?? null;
127 
128  ‪$container->get('boot.state')->done = false;
129  ‪$container->get('boot.state')->complete = false;
130  $assetsCache = ‪$container->get('cache.assets');
131  PageRenderer::setCache($assetsCache);
132  $eventDispatcher = ‪$container->get(EventDispatcherInterface::class);
134  ‪Bootstrap::loadTypo3LoadedExtAndExtLocalconf($allowCaching, ‪$container->get('cache.core'));
136  ‪$GLOBALS['BE_USER'] = $beUserBackup;
137  ‪$container->get('boot.state')->done = true;
138  ‪Bootstrap::loadBaseTca($allowCaching, ‪$container->get('cache.core'));
139  ‪Bootstrap::loadExtTables($allowCaching, ‪$container->get('cache.core'));
140  ‪$container->get('boot.state')->complete = true;
141  $eventDispatcher->dispatch(new ‪BootCompletedEvent($allowCaching));
142 
143  if ($resetContainer) {
144  $this->‪makeCurrent(null, $backup);
145  }
146 
147  return ‪$container;
148  }
149 
150  public function ‪resetGlobalContainer(): void
151  {
152  $this->‪makeCurrent(null, []);
153  }
154 
155  public function ‪getFailsafeContainer(): ContainerInterface
156  {
158  }
159 }
‪TYPO3\CMS\Core\Core\BootService\__construct
‪__construct(ContainerBuilder $containerBuilder, ContainerInterface $failsafeContainer)
Definition: BootService.php:40
‪TYPO3\CMS\Core\Core\BootService\makeCurrent
‪array makeCurrent(ContainerInterface $container=null, array $backup=[])
Definition: BootService.php:85
‪TYPO3\CMS\Core\Core\Bootstrap\createPackageCache
‪static PackageCacheInterface createPackageCache(FrontendInterface $coreCache)
Definition: Bootstrap.php:266
‪TYPO3\CMS\Core\Core\Bootstrap\loadTypo3LoadedExtAndExtLocalconf
‪static loadTypo3LoadedExtAndExtLocalconf($allowCaching=true, FrontendInterface $coreCache=null)
Definition: Bootstrap.php:287
‪TYPO3\CMS\Core\Core\BootService\loadExtLocalconfDatabaseAndExtTables
‪ContainerInterface loadExtLocalconfDatabaseAndExtTables(bool $resetContainer=false, bool $allowCaching=true)
Definition: BootService.php:121
‪TYPO3\CMS\Core\Core\Bootstrap\unsetReservedGlobalVariables
‪static unsetReservedGlobalVariables()
Definition: Bootstrap.php:481
‪TYPO3\CMS\Core\Core\BootService\getFailsafeContainer
‪getFailsafeContainer()
Definition: BootService.php:155
‪TYPO3\CMS\Core\Core\Bootstrap\createCache
‪static FrontendInterface createCache(string $identifier, bool $disableCaching=false)
Definition: Bootstrap.php:330
‪TYPO3\CMS\Core\Core\BootService
Definition: BootService.php:33
‪TYPO3\CMS\Core\Core\BootService\$failsafeContainer
‪ContainerInterface $failsafeContainer
Definition: BootService.php:36
‪TYPO3\CMS\Core\Core\BootService\getContainer
‪getContainer(bool $allowCaching=true)
Definition: BootService.php:46
‪TYPO3\CMS\Core\Core\Bootstrap\loadBaseTca
‪static loadBaseTca(bool $allowCaching=true, FrontendInterface $coreCache=null)
Definition: Bootstrap.php:502
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Core\Core\BootService\prepareContainer
‪prepareContainer(bool $allowCaching=true)
Definition: BootService.php:51
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\setPackageManager
‪static setPackageManager(PackageManager $packageManager)
Definition: ExtensionManagementUtility.php:66
‪TYPO3\CMS\Core\Core\BootService\resetGlobalContainer
‪resetGlobalContainer()
Definition: BootService.php:150
‪TYPO3\CMS\Core\Core\BootService\$containerBuilder
‪ContainerBuilder $containerBuilder
Definition: BootService.php:34
‪TYPO3\CMS\Core\Core\Event\BootCompletedEvent
Definition: BootCompletedEvent.php:24
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static bool isComposerMode()
Definition: Environment.php:152
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core
Definition: ApplicationContext.php:16
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\setEventDispatcher
‪static setEventDispatcher(EventDispatcherInterface $eventDispatcher)
Definition: ExtensionManagementUtility.php:81
‪TYPO3\CMS\Core\Core\Bootstrap\loadExtTables
‪static loadExtTables(bool $allowCaching=true, FrontendInterface $coreCache=null)
Definition: Bootstrap.php:532
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Core\BootService\$container
‪ContainerInterface $container
Definition: BootService.php:38