&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
$fnSuffix
) {
- if (!\Civi\Core\Container::isContainerBooted()) {
- $prebootHooks = ['civicrm_container', 'civicrm_entityTypes'];
- // 'civicrm_config' ?
- if (in_array($fnSuffix, $prebootHooks)) {
- $count = is_array($names) ? count($names) : $names;
- return $this->invokeViaUF($count, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $fnSuffix);
- }
- else {
- // TODO: Emit a warning, eg
- // error_log("Warning: hook_$fnSuffix fired prematurely. Dropped.");
- return;
- }
- }
-
if (!is_array($names)) {
// We were called with the old contract wherein $names is actually an int.
// Symfony dispatcher requires some kind of name.
* @return \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
public static function dispatcher() {
- return Civi\Core\Container::singleton()->get('dispatcher');
+ // NOTE: The dispatcher object is initially created as a boot service
+ // (ie `dispatcher.boot`). For compatibility with the container (eg
+ // `RegisterListenersPass` and `createEventDispatcher` addons),
+ // it is also available as the `dispatcher` service.
+ //
+ // The 'dispatcher.boot' and 'dispatcher' services are the same object,
+ // but 'dispatcher.boot' is resolvable earlier during bootstrap.
+ return Civi\Core\Container::getBootService('dispatcher.boot');
}
/**
$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();
+ $bootServices['dispatcher.boot']->setDispatchPolicy([
+ // Quality control: during pre-boot, we can register hook listeners - but not dispatch them.
+ '/./' => 'not-ready',
+ ]);
+
$class = $runtime->userFrameworkClass;
$bootServices['userSystem'] = $userSystem = new $class();
$userSystem->initialize();
$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);