Commit 87959326 authored by Benni Mack's avatar Benni Mack Committed by Benjamin Franzke
Browse files

[FEATURE] Add BootCompletedEvent

This change adds a new PSR-14 based event to hook into
the booting process after all configuration has been set up
and TYPO3 has fully booted.

This event replaces the existing
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing']
hook and its interface
TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface

Resolves: #95065
Releases: master
Change-Id: Ibe6f1b255d641f2dd8fc85c2abbaf5e4c43d7ae6
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70834

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Benjamin Franzke's avatarBenjamin Franzke <bfr@qbus.de>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Benjamin Franzke's avatarBenjamin Franzke <bfr@qbus.de>
parent 3c00759d
......@@ -19,6 +19,7 @@ namespace TYPO3\CMS\Core\Core;
use Psr\Container\ContainerInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Core\Core\Event\BootCompletedEvent;
use TYPO3\CMS\Core\DependencyInjection\ContainerBuilder;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Page\PageRenderer;
......@@ -137,6 +138,7 @@ class BootService
Bootstrap::loadBaseTca($allowCaching);
Bootstrap::loadExtTables($allowCaching);
$container->get('boot.state')->complete = true;
$eventDispatcher->dispatch(new BootCompletedEvent($allowCaching));
if ($resetContainer) {
$this->makeCurrent(null, $backup);
......
......@@ -31,6 +31,7 @@ use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend;
use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
use TYPO3\CMS\Core\Configuration\ConfigurationManager;
use TYPO3\CMS\Core\Core\Event\BootCompletedEvent;
use TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface;
use TYPO3\CMS\Core\DependencyInjection\Cache\ContainerBackend;
use TYPO3\CMS\Core\DependencyInjection\ContainerBuilder;
......@@ -155,14 +156,16 @@ class Bootstrap
return $container;
}
$eventDispatcher = $container->get(EventDispatcherInterface::class);
PageRenderer::setCache($assetsCache);
ExtensionManagementUtility::setEventDispatcher($container->get(EventDispatcherInterface::class));
ExtensionManagementUtility::setEventDispatcher($eventDispatcher);
static::loadTypo3LoadedExtAndExtLocalconf(true, $coreCache);
static::unsetReservedGlobalVariables();
$bootState->done = true;
static::loadBaseTca(true, $coreCache);
static::checkEncryptionKey();
$bootState->complete = true;
$eventDispatcher->dispatch(new BootCompletedEvent($disableCaching));
return $container;
}
......@@ -549,9 +552,13 @@ class Bootstrap
* Check for registered ext tables hooks and run them
*
* @throws \UnexpectedValueException
* @deprecated will be removed in TYPO3 v12.0, use the PSR-14 based BootCompletedEvent instead.
*/
protected static function runExtTablesPostProcessingHooks()
{
if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'])) {
trigger_error('Using the hook $TYPO3_CONF_VARS[SC_OPTIONS][GLOBAL][extTablesInclusion-PostProcessing] will be removed in TYPO3 v12.0. in favor of the new PSR-14 BootCompletedEvent', E_USER_DEPRECATED);
}
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'] ?? [] as $className) {
/** @var \TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface $hookObject */
$hookObject = GeneralUtility::makeInstance($className);
......
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Core\Event;
/**
* Executed when TYPO3 has fully booted (after all ext_tables.php files have been processed)
*/
final class BootCompletedEvent
{
protected bool $cachingEnabled;
public function __construct(bool $cachingEnabled)
{
$this->cachingEnabled = $cachingEnabled;
}
public function isCachingEnabled(): bool
{
return $this->cachingEnabled;
}
}
......@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Core\Database;
/**
* interface for classes with hook for postprocessing extTables after loading
* @deprecated will be removed in TYPO3 v12.0. Use BootCompletedEvent instead.
*/
interface TableConfigurationPostProcessingHookInterface
{
......
.. include:: ../../Includes.txt
============================================================
Deprecation: #95065 - Hook extTablesInclusion-PostProcessing
============================================================
See :issue:`95065`
Description
===========
The TYPO3 Hook :php:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing']`
which is executed after :php`ext_tables.php` files are included has been marked
as deprecated.
The accompanied PHP Interface for such hooks
:php:`TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface` is
marked as deprecated as well.
Impact
======
If a hook is registered in a TYPO3 installation, a PHP deprecation
message is triggered.
Affected Installations
======================
TYPO3 installations with custom extensions using this hook.
Migration
=========
Migrate to PSR-14 hooks, mainly the newly introduced `BootCompletedEvent` and
the existing `AfterTcaCompilationEvent` depending on the use-case.
.. index:: PHP-API, FullyScanned, ext:core
.. include:: ../../Includes.txt
===============================================
Feature: #95065 - New PSR-14 BootCompletedEvent
===============================================
See :issue:`95065`
Description
===========
A new PSR-14 event `BootCompletedEvent` has been added to TYPO3
Core. This event is fired on every request when TYPO3 has been
fully booted, right after all configuration files have been added.
This new Event complements the `AfterTcaCompilationEvent` which
is executed after TCA configuration has been assembled.
Registration of the Event in your extensions' `Services.yaml`:
.. code-block:: yaml
MyVendor\MyPackage\Bootstrap\MyEventListener:
tags:
- name: event.listener
identifier: 'my-package/my-listener'
.. code-block:: php
class MyEventListener {
public function __invoke(BootCompletedEvent $e): void
{
// do your magic
}
}
Impact
======
Use cases for this event is to alter or to boot up extensions'
code which needs to be executed at any time, and needs
TYPO3's full configuration including all loaded extensions.
.. index:: PHP-API, ext:core
......@@ -497,4 +497,9 @@ return [
'Deprecation-94953-EditPanelRelatedFrontendFunctionality.rst',
],
],
'$GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][\'GLOBAL\'][\'extTablesInclusion-PostProcessing\']' => [
'restFiles' => [
'Deprecation-95065-HookExtTablesInclusion-PostProcessing.rst',
],
],
];
......@@ -1784,4 +1784,9 @@ return [
'Deprecation-95005-ExtbaseEmptyView.rst',
],
],
'TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface' => [
'restFiles' => [
'Deprecation-95065-HookExtTablesInclusion-PostProcessing.rst',
],
],
];
Supports Markdown
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