$container->setDefinition('dispatcher', new Definition(
'Civi\Core\CiviEventDispatcher',
- [new Reference('service_container')]
+ []
))
->setFactory([new Reference(self::SELF), 'createEventDispatcher'])->setPublic(TRUE);
}
/**
- * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* @return \Symfony\Component\EventDispatcher\EventDispatcher
*/
- public function createEventDispatcher($container) {
- $dispatcher = new CiviEventDispatcher();
- if (\CRM_Core_Config::isUpgradeMode()) {
- $dispatcher->setDispatchPolicy(\CRM_Upgrade_DispatchPolicy::get('upgrade.main'));
- }
+ public function createEventDispatcher() {
+ // Continue building on the original dispatcher created during bootstrap.
+ $dispatcher = static::getBootService('dispatcher.boot');
$dispatcher->addListener('civi.core.install', ['\Civi\Core\InstallationCanary', 'check']);
$dispatcher->addListener('civi.core.install', ['\Civi\Core\DatabaseInitializer', 'initialize']);
$bootServices['paths'] = new \Civi\Core\Paths();
+ $bootServices['dispatcher.boot'] = new CiviEventDispatcher();
+
+ // 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();
$userSystem->initialize();
\CRM_Utils_Hook::singleton(TRUE);
\CRM_Extension_System::singleton(TRUE);
\CRM_Extension_System::singleton(TRUE)->getClassLoader()->register();
+ $bootServices['dispatcher.boot']->setDispatchPolicy($mainDispatchPolicy);
$runtime->includeCustomPath();
}
\Civi::$statics[__CLASS__]['container'] = $container;
}
+ else {
+ $bootServices['dispatcher.boot']->setDispatchPolicy($mainDispatchPolicy);
+ }
}
public static function getBootService($name) {