Commit 11c7e844 authored by Oliver Bartsch's avatar Oliver Bartsch
Browse files

[BUGFIX] Push PackageManager to ExtensionManagementUtility in Bootstrap

In order to allow conditional service registration based on
ExtensionManagementUtility::isLoaded() checks in Services.php,
the PackageManager is pushed to ExtensionManagementUtility
before container creation. This has been the case prior to #91500
in order to support runtime activated packages, but got removed
as isLoaded() checks in Services.php have never been an intended
usecase.

They have been documented in example code nonetheless
and therefore usage is now fixed:
https://docs.typo3.org/c/typo3/cms-dashboard/master/en-us/Configuration/WidgetRegistration.html#services-php-file



Documentation should be adapted to recommend conditional
services checks (ContainerBuilder::hasDefinition) instead.
Once that is done, isLoaded() in Services.php can be marked as
deprecated in future patches.

Resolves: #95327
Related: #91500
Releases: master
Signed-off-by: Benjamin Franzke's avatarBenjamin Franzke <bfr@qbus.de>
Change-Id: Ifec470bd6364727ec0d9a5937106e6c94c0e18c2
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/71214

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
parent b27044e6
......@@ -137,18 +137,32 @@ class Bootstrap
'boot.state' => $bootState,
]);
// Push PackageManager instance to ExtensionManagementUtility to support ::isLoaded() checks in Services.php
//
// Note that ExtensionManagementUtility() usage in Services.php has never been an intended usage,
// but it was technically possible in TYPO3 v10 as a side effect of runtime activated packages,
// and therefore got documented in example code:
// https://docs.typo3.org/c/typo3/cms-dashboard/10.4/en-us/Configuration/WidgetRegistration.html#services-php-file
//
// Container builds should generally be stateless and should only take explicit service configuration and ContainerBuilder
// build-state into account. Therefore ExtensionManagementUtility usage in Services.php should generally be avoided,
// and be replaced by service checks, e.g. ContainerBuilder->hasDefinition(ClassNameOfOptionalDependency::class)
// (combined with package suggest definition in composer.json/ext_emconf.php to ensure extension ordering is correct)
//
// @todo: Adapt documentation and maybe log a deprecation notice if ::isLoaded() is used during container builds.
ExtensionManagementUtility::setPackageManager($packageManager);
GeneralUtility::setSingletonInstance(PackageManager::class, $packageManager);
$container = $builder->createDependencyInjectionContainer($packageManager, $dependencyInjectionContainerCache, $failsafe);
// Push the container to GeneralUtility as we want to make sure its
// makeInstance() method creates classes using the container from now on.
GeneralUtility::setContainer($container);
// Reset LogManager singleton instance in order for GeneralUtility::makeInstance()
// to proxy LogManager retrieval to ContainerInterface->get() from now on.
// Reset singleton instances in order for GeneralUtility::makeInstance() to use
// ContainerInterface->get() for early services from now on.
GeneralUtility::removeSingletonInstance(LogManager::class, $logManager);
// Push PackageManager instance to ExtensionManagementUtility
ExtensionManagementUtility::setPackageManager($packageManager);
GeneralUtility::removeSingletonInstance(PackageManager::class, $packageManager);
if ($failsafe) {
$bootState->done = true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment