‪TYPO3CMS  ‪main
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;
27 
32 {
33  private ContainerBuilder ‪$containerBuilder;
34 
35  private ContainerInterface ‪$failsafeContainer;
36 
37  private ?ContainerInterface ‪$container = null;
38 
39  public function ‪__construct(ContainerBuilder ‪$containerBuilder, ContainerInterface ‪$failsafeContainer)
40  {
41  $this->containerBuilder = ‪$containerBuilder;
42  $this->failsafeContainer = ‪$failsafeContainer;
43  }
44 
45  public function ‪getContainer(bool $allowCaching = true): ContainerInterface
46  {
47  return $this->container ?? $this->‪prepareContainer($allowCaching);
48  }
49 
50  private function ‪prepareContainer(bool $allowCaching = true): ContainerInterface
51  {
52  $packageManager = $this->failsafeContainer->get(PackageManager::class);
53  $dependencyInjectionContainerCache = $this->failsafeContainer->get('cache.di');
54 
55  $failsafe = false;
56 
57  // Build a non-failsafe container which is required for loading ext_localconf
58  $this->container = $this->containerBuilder->createDependencyInjectionContainer($packageManager, $dependencyInjectionContainerCache, $failsafe);
59  $this->container->set('_early.boot-service', $this);
60  if ($allowCaching) {
61  $this->container->get('boot.state')->cacheDisabled = false;
62  $coreCache = ‪Bootstrap::createCache('core');
63  // Core cache is initialized with a NullBackend in failsafe mode.
64  // Replace it with a new cache that uses the real backend.
65  $this->container->set('_early.cache.core', $coreCache);
66  $this->container->set('_early.cache.assets', ‪Bootstrap::createCache('assets'));
68  $this->container->get(PackageManager::class)->setPackageCache(‪Bootstrap::createPackageCache($coreCache));
69  }
70  }
71 
72  return ‪$this->container;
73  }
74 
80  public function ‪makeCurrent(ContainerInterface ‪$container = null, array $backup = []): array
81  {
82  ‪$container = ‪$container ?? $backup['container'] ?? ‪$this->failsafeContainer;
83 
84  $newBackup = [
85  'singletonInstances' => GeneralUtility::getSingletonInstances(),
86  'container' => GeneralUtility::getContainer(),
87  ];
88 
89  GeneralUtility::purgeInstances();
90 
91  // Set global state to the non-failsafe container and it's instances
92  GeneralUtility::setContainer(‪$container);
94 
95  $backupSingletonInstances = $backup['singletonInstances'] ?? [];
96  foreach ($backupSingletonInstances as $className => $instance) {
97  GeneralUtility::setSingletonInstance($className, $instance);
98  }
99 
100  return $newBackup;
101  }
102 
115  public function ‪loadExtLocalconfDatabaseAndExtTables(bool $resetContainer = false, bool $allowCaching = true): ContainerInterface
116  {
117  ‪$container = $this->‪getContainer($allowCaching);
118 
119  $backup = $this->‪makeCurrent($container);
120  $beUserBackup = ‪$GLOBALS['BE_USER'] ?? null;
121 
122  ‪$container->get('boot.state')->complete = false;
123  $eventDispatcher = ‪$container->get(EventDispatcherInterface::class);
125  ‪Bootstrap::loadTypo3LoadedExtAndExtLocalconf($allowCaching, ‪$container->get('cache.core'));
127  ‪$GLOBALS['BE_USER'] = $beUserBackup;
128  ‪Bootstrap::loadBaseTca($allowCaching, ‪$container->get('cache.core'));
129  ‪$container->get('boot.state')->complete = true;
130  $eventDispatcher->dispatch(new ‪BootCompletedEvent($allowCaching));
131  ‪Bootstrap::loadExtTables($allowCaching, ‪$container->get('cache.core'));
132 
133  if ($resetContainer) {
134  $this->‪makeCurrent(null, $backup);
135  }
136 
137  return ‪$container;
138  }
139 
140  public function ‪resetGlobalContainer(): void
141  {
142  $this->‪makeCurrent(null, []);
143  }
144 
145  public function ‪getFailsafeContainer(): ContainerInterface
146  {
148  }
149 }
‪TYPO3\CMS\Core\Core\BootService\__construct
‪__construct(ContainerBuilder $containerBuilder, ContainerInterface $failsafeContainer)
Definition: BootService.php:39
‪TYPO3\CMS\Core\Core\Bootstrap\loadTypo3LoadedExtAndExtLocalconf
‪static loadTypo3LoadedExtAndExtLocalconf($allowCaching=true, FrontendInterface $coreCache=null)
Definition: Bootstrap.php:308
‪TYPO3\CMS\Core\Core\Bootstrap\unsetReservedGlobalVariables
‪static unsetReservedGlobalVariables()
Definition: Bootstrap.php:477
‪TYPO3\CMS\Core\Core\BootService\loadExtLocalconfDatabaseAndExtTables
‪loadExtLocalconfDatabaseAndExtTables(bool $resetContainer=false, bool $allowCaching=true)
Definition: BootService.php:115
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static isComposerMode()
Definition: Environment.php:137
‪TYPO3\CMS\Core\Core\Bootstrap\createPackageCache
‪static createPackageCache(FrontendInterface $coreCache)
Definition: Bootstrap.php:288
‪TYPO3\CMS\Core\Core\BootService\getFailsafeContainer
‪getFailsafeContainer()
Definition: BootService.php:145
‪TYPO3\CMS\Core\Core\BootService
Definition: BootService.php:32
‪TYPO3\CMS\Core\Core\BootService\$failsafeContainer
‪ContainerInterface $failsafeContainer
Definition: BootService.php:35
‪TYPO3\CMS\Core\Core\BootService\getContainer
‪getContainer(bool $allowCaching=true)
Definition: BootService.php:45
‪TYPO3\CMS\Core\Core\Bootstrap\loadBaseTca
‪static loadBaseTca(bool $allowCaching=true, FrontendInterface $coreCache=null)
Definition: Bootstrap.php:493
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:40
‪TYPO3\CMS\Core\Core\BootService\prepareContainer
‪prepareContainer(bool $allowCaching=true)
Definition: BootService.php:50
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\setPackageManager
‪static setPackageManager(PackageManager $packageManager)
Definition: ExtensionManagementUtility.php:61
‪TYPO3\CMS\Core\Core\BootService\resetGlobalContainer
‪resetGlobalContainer()
Definition: BootService.php:140
‪TYPO3\CMS\Core\Core\BootService\$containerBuilder
‪ContainerBuilder $containerBuilder
Definition: BootService.php:33
‪TYPO3\CMS\Core\Core\Event\BootCompletedEvent
Definition: BootCompletedEvent.php:24
‪TYPO3\CMS\Core\Core\Bootstrap\createCache
‪static createCache(string $identifier, bool $disableCaching=false)
Definition: Bootstrap.php:347
‪$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:71
‪TYPO3\CMS\Core\Core\Bootstrap\loadExtTables
‪static loadExtTables(bool $allowCaching=true, FrontendInterface $coreCache=null)
Definition: Bootstrap.php:523
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\Core\BootService\$container
‪ContainerInterface $container
Definition: BootService.php:37
‪TYPO3\CMS\Core\Core\BootService\makeCurrent
‪makeCurrent(ContainerInterface $container=null, array $backup=[])
Definition: BootService.php:80