From 27e05c5c35d0607854588f68c4237d5aa9dc8bc1 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 14 Jul 2020 20:38:09 -0700 Subject: [PATCH] Civi::dispatcher() - Extend protection against pre-boot hooks Before: The protection extends up until `createLockManager()` After: The protection extends up until `CRM_Extension_System...->register()` --- Civi/Core/Container.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index c8a107014b..1c3374f98b 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -499,10 +499,15 @@ class Container { $bootServices['paths'] = new \Civi\Core\Paths(); $bootServices['dispatcher.boot'] = new CiviEventDispatcher(); - $bootServices['dispatcher.boot']->setDispatchPolicy([ - // Quality control: during pre-boot, we can register hook listeners - but not dispatch them. - '/./' => 'not-ready', - ]); + + // Quality control: There should be no pre-boot hooks because they make it harder to understand/support/refactor. + // If a pre-boot hook sneaks in, we'll raise an error. + $bootDispatchPolicy = [ + '/^hook_/' => 'not-ready', + '/^civi\./' => 'run', + ]; + $mainDispatchPolicy = \CRM_Core_Config::isUpgradeMode() ? \CRM_Upgrade_DispatchPolicy::get('upgrade.main') : NULL; + $bootServices['dispatcher.boot']->setDispatchPolicy($bootDispatchPolicy); $class = $runtime->userFrameworkClass; $bootServices['userSystem'] = $userSystem = new $class(); @@ -520,13 +525,12 @@ class Container { $bootServices['lockManager'] = self::createLockManager(); - $bootServices['dispatcher.boot']->setDispatchPolicy(\CRM_Core_Config::isUpgradeMode() ? \CRM_Upgrade_DispatchPolicy::get('upgrade.main') : NULL); - if ($loadFromDB && $runtime->dsn) { \CRM_Core_DAO::init($runtime->dsn); \CRM_Utils_Hook::singleton(TRUE); \CRM_Extension_System::singleton(TRUE); \CRM_Extension_System::singleton(TRUE)->getClassLoader()->register(); + $bootServices['dispatcher.boot']->setDispatchPolicy($mainDispatchPolicy); $runtime->includeCustomPath(); @@ -537,6 +541,9 @@ class Container { } \Civi::$statics[__CLASS__]['container'] = $container; } + else { + $bootServices['dispatcher.boot']->setDispatchPolicy($mainDispatchPolicy); + } } public static function getBootService($name) { -- 2.25.1