diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index 6a1472390d54..c1d7ec1a1042 100644 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -36,7 +36,7 @@ public static function getMappings($filters = NULL) { if ($_action_mapping === NULL) { $event = \Civi::dispatcher() - ->dispatch(\Civi\ActionSchedule\Events::MAPPINGS, + ->dispatch('civi.actionSchedule.getMappings', new \Civi\ActionSchedule\Event\MappingRegisterEvent()); $_action_mapping = $event->getMappings(); } @@ -516,7 +516,7 @@ protected static function prepareMailingQuery($mapping, $actionSchedule) { \Civi::dispatcher() ->dispatch( - \Civi\ActionSchedule\Events::MAILING_QUERY, + 'civi.actionSchedule.prepareMailingQuery', new \Civi\ActionSchedule\Event\MailingQueryEvent($actionSchedule, $mapping, $select) ); diff --git a/CRM/Core/Config.php b/CRM/Core/Config.php index f2f28ccd08eb..a27d424d6ae3 100644 --- a/CRM/Core/Config.php +++ b/CRM/Core/Config.php @@ -560,7 +560,7 @@ public function handleFirstRun() { } // OK, this looks new. - Civi::dispatcher()->dispatch(\Civi\Core\Event\SystemInstallEvent::EVENT_NAME, new \Civi\Core\Event\SystemInstallEvent()); + Civi::dispatcher()->dispatch('civi.core.install', new \Civi\Core\Event\SystemInstallEvent()); Civi::settings()->set('installed', 1); } diff --git a/Civi/API/Event/AuthorizeEvent.php b/Civi/API/Event/AuthorizeEvent.php index 82c63438247f..9d146a9b40f6 100644 --- a/Civi/API/Event/AuthorizeEvent.php +++ b/Civi/API/Event/AuthorizeEvent.php @@ -14,6 +14,12 @@ /** * Class AuthorizeEvent * @package Civi\API\Event + * + * Determine whether the API request is allowed for the current user. + * For successful execution, at least one listener must invoke + * $event->authorize(). + * + * Event name: 'civi.api.authorize' */ class AuthorizeEvent extends Event { /** diff --git a/Civi/API/Event/ExceptionEvent.php b/Civi/API/Event/ExceptionEvent.php index 8860e51724ed..3b95ea539b1d 100644 --- a/Civi/API/Event/ExceptionEvent.php +++ b/Civi/API/Event/ExceptionEvent.php @@ -12,8 +12,9 @@ namespace Civi\API\Event; /** - * Class ExceptionEvent - * @package Civi\API\Event + * Handle any exceptions that occur while processing an API request. + * + * Event name: 'civi.api.exception' */ class ExceptionEvent extends Event { diff --git a/Civi/API/Event/PrepareEvent.php b/Civi/API/Event/PrepareEvent.php index 8fcf7fb134c5..1c6576173c89 100644 --- a/Civi/API/Event/PrepareEvent.php +++ b/Civi/API/Event/PrepareEvent.php @@ -16,6 +16,10 @@ /** * Class PrepareEvent * @package Civi\API\Event + * + * Apply any pre-execution filtering to the API request. + * + * Event name: 'civi.api.prepare' */ class PrepareEvent extends Event { diff --git a/Civi/API/Event/ResolveEvent.php b/Civi/API/Event/ResolveEvent.php index b0f6f01a31c8..8d574a032782 100644 --- a/Civi/API/Event/ResolveEvent.php +++ b/Civi/API/Event/ResolveEvent.php @@ -14,6 +14,12 @@ /** * Class ResolveEvent * @package Civi\API\Event + * + * Determine which API provider executes the given request. For successful + * execution, at least one listener must invoke + * $event->setProvider($provider). + * + * Event name: 'civi.api.resolve' */ class ResolveEvent extends Event { diff --git a/Civi/API/Event/RespondEvent.php b/Civi/API/Event/RespondEvent.php index 8f560b610976..462cc6edab22 100644 --- a/Civi/API/Event/RespondEvent.php +++ b/Civi/API/Event/RespondEvent.php @@ -14,6 +14,10 @@ /** * Class RespondEvent * @package Civi\API\Event + * + * Apply post-execution filtering to the API request/response. + * + * Event name: 'civi.api.respond' */ class RespondEvent extends Event { /** diff --git a/Civi/API/Events.php b/Civi/API/Events.php index ff6f4caa1d5a..6bbecb8f037f 100644 --- a/Civi/API/Events.php +++ b/Civi/API/Events.php @@ -22,27 +22,20 @@ class Events { /** - * Determine whether the API request is allowed for the current user. - * For successful execution, at least one listener must invoke - * $event->authorize(). - * * @see AuthorizeEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const AUTHORIZE = 'civi.api.authorize'; /** - * Determine which API provider executes the given request. For successful - * execution, at least one listener must invoke - * $event->setProvider($provider). - * * @see ResolveEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const RESOLVE = 'civi.api.resolve'; /** - * Apply pre-execution logic - * * @see PrepareEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const PREPARE = 'civi.api.prepare'; @@ -50,6 +43,7 @@ class Events { * Apply post-execution logic * * @see RespondEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const RESPOND = 'civi.api.respond'; @@ -57,6 +51,7 @@ class Events { * Handle any exceptions. * * @see ExceptionEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const EXCEPTION = 'civi.api.exception'; @@ -80,11 +75,11 @@ class Events { */ public static function allEvents() { return [ - self::AUTHORIZE, - self::EXCEPTION, - self::PREPARE, - self::RESOLVE, - self::RESPOND, + 'civi.api.authorize', + 'civi.api.exception', + 'civi.api.prepare', + 'civi.api.resolve', + 'civi.api.respond', ]; } @@ -93,11 +88,11 @@ public static function allEvents() { * @see \CRM_Utils_Hook::eventDefs */ public static function hookEventDefs($e) { - $e->inspector->addEventClass(self::AUTHORIZE, 'Civi\API\Event\AuthorizeEvent'); - $e->inspector->addEventClass(self::EXCEPTION, 'Civi\API\Event\ExceptionEvent'); - $e->inspector->addEventClass(self::PREPARE, 'Civi\API\Event\PrepareEvent'); - $e->inspector->addEventClass(self::RESOLVE, 'Civi\API\Event\ResolveEvent'); - $e->inspector->addEventClass(self::RESPOND, 'Civi\API\Event\RespondEvent'); + $e->inspector->addEventClass('civi.api.authorize', 'Civi\API\Event\AuthorizeEvent'); + $e->inspector->addEventClass('civi.api.exception', 'Civi\API\Event\ExceptionEvent'); + $e->inspector->addEventClass('civi.api.prepare', 'Civi\API\Event\PrepareEvent'); + $e->inspector->addEventClass('civi.api.resolve', 'Civi\API\Event\ResolveEvent'); + $e->inspector->addEventClass('civi.api.respond', 'Civi\API\Event\RespondEvent'); } } diff --git a/Civi/API/Kernel.php b/Civi/API/Kernel.php index 13e55c34455d..feb8b662e45c 100644 --- a/Civi/API/Kernel.php +++ b/Civi/API/Kernel.php @@ -83,7 +83,7 @@ public function runSafe($entity, $action, $params) { } catch (\Exception $e) { if ($apiRequest) { - $this->dispatcher->dispatch(Events::EXCEPTION, new ExceptionEvent($e, NULL, $apiRequest, $this)); + $this->dispatcher->dispatch('civi.api.exception', new ExceptionEvent($e, NULL, $apiRequest, $this)); } if ($e instanceof \PEAR_Exception) { @@ -197,7 +197,7 @@ protected function validate($apiRequest) { */ public function resolve($apiRequest) { /** @var \Civi\API\Event\ResolveEvent $resolveEvent */ - $resolveEvent = $this->dispatcher->dispatch(Events::RESOLVE, new ResolveEvent($apiRequest, $this)); + $resolveEvent = $this->dispatcher->dispatch('civi.api.resolve', new ResolveEvent($apiRequest, $this)); $apiRequest = $resolveEvent->getApiRequest(); if (!$resolveEvent->getApiProvider()) { throw new \Civi\API\Exception\NotImplementedException("API (" . $apiRequest['entity'] . ", " . $apiRequest['action'] . ") does not exist (join the API team and implement it!)"); @@ -216,7 +216,7 @@ public function resolve($apiRequest) { */ public function authorize($apiProvider, $apiRequest) { /** @var \Civi\API\Event\AuthorizeEvent $event */ - $event = $this->dispatcher->dispatch(Events::AUTHORIZE, new AuthorizeEvent($apiProvider, $apiRequest, $this)); + $event = $this->dispatcher->dispatch('civi.api.authorize', new AuthorizeEvent($apiProvider, $apiRequest, $this)); if (!$event->isAuthorized()) { throw new \Civi\API\Exception\UnauthorizedException("Authorization failed"); } @@ -235,7 +235,7 @@ public function authorize($apiProvider, $apiRequest) { */ public function prepare($apiProvider, $apiRequest) { /** @var \Civi\API\Event\PrepareEvent $event */ - $event = $this->dispatcher->dispatch(Events::PREPARE, new PrepareEvent($apiProvider, $apiRequest, $this)); + $event = $this->dispatcher->dispatch('civi.api.prepare', new PrepareEvent($apiProvider, $apiRequest, $this)); return [$event->getApiProvider(), $event->getApiRequest()]; } @@ -253,7 +253,7 @@ public function prepare($apiProvider, $apiRequest) { */ public function respond($apiProvider, $apiRequest, $result) { /** @var \Civi\API\Event\RespondEvent $event */ - $event = $this->dispatcher->dispatch(Events::RESPOND, new RespondEvent($apiProvider, $apiRequest, $result, $this)); + $event = $this->dispatcher->dispatch('civi.api.respond', new RespondEvent($apiProvider, $apiRequest, $result, $this)); return $event->getResponse(); } diff --git a/Civi/API/Provider/AdhocProvider.php b/Civi/API/Provider/AdhocProvider.php index fcab72e1821f..f7855635a821 100644 --- a/Civi/API/Provider/AdhocProvider.php +++ b/Civi/API/Provider/AdhocProvider.php @@ -27,10 +27,10 @@ public static function getSubscribedEvents() { // to override standard implementations -- which is // handy for testing/mocking. return [ - Events::RESOLVE => [ + 'civi.api.resolve' => [ ['onApiResolve', Events::W_EARLY], ], - Events::AUTHORIZE => [ + 'civi.api.authorize' => [ ['onApiAuthorize', Events::W_EARLY], ], ]; diff --git a/Civi/API/Provider/MagicFunctionProvider.php b/Civi/API/Provider/MagicFunctionProvider.php index 8fab3ff19cab..febcaa06226a 100644 --- a/Civi/API/Provider/MagicFunctionProvider.php +++ b/Civi/API/Provider/MagicFunctionProvider.php @@ -25,7 +25,7 @@ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterfa */ public static function getSubscribedEvents() { return [ - Events::RESOLVE => [ + 'civi.api.resolve' => [ ['onApiResolve', Events::W_MIDDLE], ], ]; diff --git a/Civi/API/Provider/ReflectionProvider.php b/Civi/API/Provider/ReflectionProvider.php index 87b95bb18b72..ac432b8fa310 100644 --- a/Civi/API/Provider/ReflectionProvider.php +++ b/Civi/API/Provider/ReflectionProvider.php @@ -24,11 +24,11 @@ class ReflectionProvider implements EventSubscriberInterface, ProviderInterface */ public static function getSubscribedEvents() { return [ - Events::RESOLVE => [ + 'civi.api.resolve' => [ // TODO decide if we really want to override others ['onApiResolve', Events::W_EARLY], ], - Events::AUTHORIZE => [ + 'civi.api.authorize' => [ // TODO decide if we really want to override others ['onApiAuthorize', Events::W_EARLY], ], diff --git a/Civi/API/Provider/StaticProvider.php b/Civi/API/Provider/StaticProvider.php index 31dc36c7a6ed..138d561b1fd5 100644 --- a/Civi/API/Provider/StaticProvider.php +++ b/Civi/API/Provider/StaticProvider.php @@ -29,10 +29,10 @@ class StaticProvider extends AdhocProvider { */ public static function getSubscribedEvents() { return [ - Events::RESOLVE => [ + 'civi.api.resolve' => [ ['onApiResolve', Events::W_MIDDLE], ], - Events::AUTHORIZE => [ + 'civi.api.authorize' => [ ['onApiAuthorize', Events::W_MIDDLE], ], ]; diff --git a/Civi/API/Subscriber/APIv3SchemaAdapter.php b/Civi/API/Subscriber/APIv3SchemaAdapter.php index a2ebabd45000..fa15949348b4 100644 --- a/Civi/API/Subscriber/APIv3SchemaAdapter.php +++ b/Civi/API/Subscriber/APIv3SchemaAdapter.php @@ -25,7 +25,7 @@ class APIv3SchemaAdapter implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::PREPARE => [ + 'civi.api.prepare' => [ ['onApiPrepare', Events::W_MIDDLE], ['onApiPrepare_validate', Events::W_LATE], ], diff --git a/Civi/API/Subscriber/ChainSubscriber.php b/Civi/API/Subscriber/ChainSubscriber.php index 883449563381..ff4f79256e1a 100644 --- a/Civi/API/Subscriber/ChainSubscriber.php +++ b/Civi/API/Subscriber/ChainSubscriber.php @@ -40,7 +40,7 @@ class ChainSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::RESPOND => ['onApiRespond', Events::W_EARLY], + 'civi.api.respond' => ['onApiRespond', Events::W_EARLY], ]; } diff --git a/Civi/API/Subscriber/DebugSubscriber.php b/Civi/API/Subscriber/DebugSubscriber.php index 88f529f972e9..ac1abad89494 100644 --- a/Civi/API/Subscriber/DebugSubscriber.php +++ b/Civi/API/Subscriber/DebugSubscriber.php @@ -11,7 +11,6 @@ namespace Civi\API\Subscriber; -use Civi\API\Events; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -30,8 +29,8 @@ class DebugSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::PREPARE => ['onApiPrepare', 999], - Events::RESPOND => ['onApiRespond', -999], + 'civi.api.prepare' => ['onApiPrepare', 999], + 'civi.api.respond' => ['onApiRespond', -999], ]; } diff --git a/Civi/API/Subscriber/DynamicFKAuthorization.php b/Civi/API/Subscriber/DynamicFKAuthorization.php index ecaf5ff428ec..6a19cded0350 100644 --- a/Civi/API/Subscriber/DynamicFKAuthorization.php +++ b/Civi/API/Subscriber/DynamicFKAuthorization.php @@ -36,7 +36,7 @@ class DynamicFKAuthorization implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::AUTHORIZE => [ + 'civi.api.authorize' => [ ['onApiAuthorize', Events::W_EARLY], ], ]; diff --git a/Civi/API/Subscriber/I18nSubscriber.php b/Civi/API/Subscriber/I18nSubscriber.php index f89964c0b2a2..d3b732972a2a 100644 --- a/Civi/API/Subscriber/I18nSubscriber.php +++ b/Civi/API/Subscriber/I18nSubscriber.php @@ -32,8 +32,8 @@ class I18nSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::PREPARE => ['onApiPrepare', Events::W_MIDDLE], - Events::RESPOND => ['onApiRespond', Events::W_LATE], + 'civi.api.prepare' => ['onApiPrepare', Events::W_MIDDLE], + 'civi.api.respond' => ['onApiRespond', Events::W_LATE], ]; } diff --git a/Civi/API/Subscriber/PermissionCheck.php b/Civi/API/Subscriber/PermissionCheck.php index bc2f18af6adb..9441800733ce 100644 --- a/Civi/API/Subscriber/PermissionCheck.php +++ b/Civi/API/Subscriber/PermissionCheck.php @@ -26,7 +26,7 @@ class PermissionCheck implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::AUTHORIZE => [ + 'civi.api.authorize' => [ ['onApiAuthorize', Events::W_LATE], ], ]; diff --git a/Civi/API/Subscriber/TransactionSubscriber.php b/Civi/API/Subscriber/TransactionSubscriber.php index 8e7ff6a31bdb..88f34f69b294 100644 --- a/Civi/API/Subscriber/TransactionSubscriber.php +++ b/Civi/API/Subscriber/TransactionSubscriber.php @@ -34,9 +34,9 @@ class TransactionSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::PREPARE => ['onApiPrepare', Events::W_EARLY], - Events::RESPOND => ['onApiRespond', Events::W_MIDDLE], - Events::EXCEPTION => ['onApiException', Events::W_EARLY], + 'civi.api.prepare' => ['onApiPrepare', Events::W_EARLY], + 'civi.api.respond' => ['onApiRespond', Events::W_MIDDLE], + 'civi.api.exception' => ['onApiException', Events::W_EARLY], ]; } diff --git a/Civi/API/Subscriber/WhitelistSubscriber.php b/Civi/API/Subscriber/WhitelistSubscriber.php index 2efd8eef96d2..3a43128364be 100644 --- a/Civi/API/Subscriber/WhitelistSubscriber.php +++ b/Civi/API/Subscriber/WhitelistSubscriber.php @@ -30,8 +30,8 @@ class WhitelistSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::AUTHORIZE => ['onApiAuthorize', Events::W_EARLY], - Events::RESPOND => ['onApiRespond', Events::W_MIDDLE], + 'civi.api.authorize' => ['onApiAuthorize', Events::W_EARLY], + 'civi.api.respond' => ['onApiRespond', Events::W_MIDDLE], ]; } diff --git a/Civi/API/Subscriber/WrapperAdapter.php b/Civi/API/Subscriber/WrapperAdapter.php index 6b90161e914a..c7216731427f 100644 --- a/Civi/API/Subscriber/WrapperAdapter.php +++ b/Civi/API/Subscriber/WrapperAdapter.php @@ -26,8 +26,8 @@ class WrapperAdapter implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::PREPARE => ['onApiPrepare', Events::W_MIDDLE], - Events::RESPOND => ['onApiRespond', Events::W_EARLY * 2], + 'civi.api.prepare' => ['onApiPrepare', Events::W_MIDDLE], + 'civi.api.respond' => ['onApiRespond', Events::W_EARLY * 2], ]; } diff --git a/Civi/ActionSchedule/Event/MailingQueryEvent.php b/Civi/ActionSchedule/Event/MailingQueryEvent.php index e8b136e84dc4..0158b41e7d43 100644 --- a/Civi/ActionSchedule/Event/MailingQueryEvent.php +++ b/Civi/ActionSchedule/Event/MailingQueryEvent.php @@ -37,6 +37,8 @@ * * (Note: When adding more JOINs, it seems typical to use !casMailingJoinType, although * some hard-code a LEFT JOIN. Don't have an explanation for why.) + * + * Event name: 'civi.actionSchedule.prepareMailingQuery' */ class MailingQueryEvent extends Event { diff --git a/Civi/ActionSchedule/Event/MappingRegisterEvent.php b/Civi/ActionSchedule/Event/MappingRegisterEvent.php index d3a29c3c5a28..ef8c7f375036 100644 --- a/Civi/ActionSchedule/Event/MappingRegisterEvent.php +++ b/Civi/ActionSchedule/Event/MappingRegisterEvent.php @@ -9,6 +9,8 @@ * @package Civi\ActionSchedule\Event * * Register any available mappings. + * + * Event name: 'civi.actionSchedule.getMappings' */ class MappingRegisterEvent extends Event { diff --git a/Civi/ActionSchedule/Events.php b/Civi/ActionSchedule/Events.php index 3ff1a385e132..7c74d56c1477 100644 --- a/Civi/ActionSchedule/Events.php +++ b/Civi/ActionSchedule/Events.php @@ -4,15 +4,14 @@ class Events { /** - * Register any available mappings. - * - * @see EntityListEvent + * @see \Civi\ActionSchedule\Event\MappingRegisterEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const MAPPINGS = 'civi.actionSchedule.getMappings'; /** - * Prepare the pre-mailing query. This query loads details about - * the contact/entity so that they're available for mail-merge. + * @see \Civi\ActionSchedule\Event\MailingQueryEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const MAILING_QUERY = 'civi.actionSchedule.prepareMailingQuery'; diff --git a/Civi/Api4/Event/Subscriber/Generic/AbstractPrepareSubscriber.php b/Civi/Api4/Event/Subscriber/Generic/AbstractPrepareSubscriber.php index aae758b2a812..3835c70d2885 100644 --- a/Civi/Api4/Event/Subscriber/Generic/AbstractPrepareSubscriber.php +++ b/Civi/Api4/Event/Subscriber/Generic/AbstractPrepareSubscriber.php @@ -22,7 +22,6 @@ namespace Civi\Api4\Event\Subscriber\Generic; use Civi\API\Event\PrepareEvent; -use Civi\API\Events; use Symfony\Component\EventDispatcher\EventSubscriberInterface; abstract class AbstractPrepareSubscriber implements EventSubscriberInterface { @@ -32,7 +31,7 @@ abstract class AbstractPrepareSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::PREPARE => 'onApiPrepare', + 'civi.api.prepare' => 'onApiPrepare', ]; } diff --git a/Civi/Api4/Event/Subscriber/PermissionCheckSubscriber.php b/Civi/Api4/Event/Subscriber/PermissionCheckSubscriber.php index 500b0c6930f8..70fecac90789 100644 --- a/Civi/Api4/Event/Subscriber/PermissionCheckSubscriber.php +++ b/Civi/Api4/Event/Subscriber/PermissionCheckSubscriber.php @@ -26,7 +26,7 @@ class PermissionCheckSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::AUTHORIZE => [ + 'civi.api.authorize' => [ ['onApiAuthorize', Events::W_LATE], ], ]; diff --git a/Civi/Api4/Provider/ActionObjectProvider.php b/Civi/Api4/Provider/ActionObjectProvider.php index b31c3d323f9a..9fa607c65e3d 100644 --- a/Civi/Api4/Provider/ActionObjectProvider.php +++ b/Civi/Api4/Provider/ActionObjectProvider.php @@ -31,7 +31,7 @@ public static function getSubscribedEvents() { // to override standard implementations -- which is // handy for testing/mocking. return [ - Events::RESOLVE => [ + 'civi.api.resolve' => [ ['onApiResolve', Events::W_EARLY], ], ]; diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index 7493eff1785d..57ee30916408 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -1,7 +1,6 @@ setDispatchPolicy(\CRM_Upgrade_DispatchPolicy::get('upgrade.main')); } - $dispatcher->addListener(SystemInstallEvent::EVENT_NAME, ['\Civi\Core\InstallationCanary', 'check']); - $dispatcher->addListener(SystemInstallEvent::EVENT_NAME, ['\Civi\Core\DatabaseInitializer', 'initialize']); - $dispatcher->addListener(SystemInstallEvent::EVENT_NAME, ['\Civi\Core\LocalizationInitializer', 'initialize']); + $dispatcher->addListener('civi.core.install', ['\Civi\Core\InstallationCanary', 'check']); + $dispatcher->addListener('civi.core.install', ['\Civi\Core\DatabaseInitializer', 'initialize']); + $dispatcher->addListener('civi.core.install', ['\Civi\Core\LocalizationInitializer', 'initialize']); $dispatcher->addListener('hook_civicrm_post', ['\CRM_Core_Transaction', 'addPostCommit'], -1000); $dispatcher->addListener('hook_civicrm_pre', ['\Civi\Core\Event\PreEvent', 'dispatchSubevent'], 100); $dispatcher->addListener('civi.dao.preDelete', ['\CRM_Core_BAO_EntityTag', 'preDeleteOtherEntity']); @@ -362,12 +361,12 @@ public function createEventDispatcher($container) { 'CRM_Core_LegacyErrorHandler', 'handleException', ], -200); - $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, ['CRM_Activity_ActionMapping', 'onRegisterActionMappings']); - $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, ['CRM_Contact_ActionMapping', 'onRegisterActionMappings']); - $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, ['CRM_Contribute_ActionMapping_ByPage', 'onRegisterActionMappings']); - $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, ['CRM_Contribute_ActionMapping_ByType', 'onRegisterActionMappings']); - $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, ['CRM_Event_ActionMapping', 'onRegisterActionMappings']); - $dispatcher->addListener(\Civi\ActionSchedule\Events::MAPPINGS, ['CRM_Member_ActionMapping', 'onRegisterActionMappings']); + $dispatcher->addListener('civi.actionSchedule.getMappings', ['CRM_Activity_ActionMapping', 'onRegisterActionMappings']); + $dispatcher->addListener('civi.actionSchedule.getMappings', ['CRM_Contact_ActionMapping', 'onRegisterActionMappings']); + $dispatcher->addListener('civi.actionSchedule.getMappings', ['CRM_Contribute_ActionMapping_ByPage', 'onRegisterActionMappings']); + $dispatcher->addListener('civi.actionSchedule.getMappings', ['CRM_Contribute_ActionMapping_ByType', 'onRegisterActionMappings']); + $dispatcher->addListener('civi.actionSchedule.getMappings', ['CRM_Event_ActionMapping', 'onRegisterActionMappings']); + $dispatcher->addListener('civi.actionSchedule.getMappings', ['CRM_Member_ActionMapping', 'onRegisterActionMappings']); return $dispatcher; } diff --git a/Civi/Core/Event/SystemInstallEvent.php b/Civi/Core/Event/SystemInstallEvent.php index f85334f9fb29..3a9193e3df3b 100644 --- a/Civi/Core/Event/SystemInstallEvent.php +++ b/Civi/Core/Event/SystemInstallEvent.php @@ -19,6 +19,8 @@ class SystemInstallEvent extends \Symfony\Component\EventDispatcher\Event { /** * The SystemInstallEvent fires once after installation - during the first page-view. + * + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const EVENT_NAME = 'civi.core.install'; @@ -27,7 +29,7 @@ class SystemInstallEvent extends \Symfony\Component\EventDispatcher\Event { * @see \CRM_Utils_Hook::eventDefs */ public static function hookEventDefs($e) { - $e->inspector->addEventClass(self::EVENT_NAME, __CLASS__); + $e->inspector->addEventClass('civi.core.install', __CLASS__); } } diff --git a/Civi/Token/AbstractTokenSubscriber.php b/Civi/Token/AbstractTokenSubscriber.php index 9af4ca685442..024f855b3eeb 100644 --- a/Civi/Token/AbstractTokenSubscriber.php +++ b/Civi/Token/AbstractTokenSubscriber.php @@ -41,9 +41,9 @@ abstract class AbstractTokenSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return [ - Events::TOKEN_REGISTER => 'registerTokens', - Events::TOKEN_EVALUATE => 'evaluateTokens', - \Civi\ActionSchedule\Events::MAILING_QUERY => 'alterActionScheduleQuery', + 'civi.token.list' => 'registerTokens', + 'civi.token.eval' => 'evaluateTokens', + 'civi.actionSchedule.prepareMailingQuery' => 'alterActionScheduleQuery', ]; } diff --git a/Civi/Token/Event/TokenRegisterEvent.php b/Civi/Token/Event/TokenRegisterEvent.php index c7fdfa01fe7b..ee867b949e89 100644 --- a/Civi/Token/Event/TokenRegisterEvent.php +++ b/Civi/Token/Event/TokenRegisterEvent.php @@ -18,6 +18,8 @@ * 'label' => ts('Default Profile URL (View Mode)'), * )); * @endcode + * + * Event name: 'civi.token.list' */ class TokenRegisterEvent extends TokenEvent { diff --git a/Civi/Token/Event/TokenRenderEvent.php b/Civi/Token/Event/TokenRenderEvent.php index 3fda8442eb66..5c1612e49ceb 100644 --- a/Civi/Token/Event/TokenRenderEvent.php +++ b/Civi/Token/Event/TokenRenderEvent.php @@ -5,13 +5,15 @@ * Class TokenRenderEvent * @package Civi\Token\Event * - * A TokenRenderEvent is fired after the TokenProcessor has rendered - * a message. + * Perform post-processing on a rendered message. A TokenRenderEvent is fired + * after the TokenProcessor has rendered a message. * - * The render event may be used for post-processing the text, but + * WARNING: The render event may be used for post-processing the text, but * it's very difficult to do substantive work in a secure, robust * way within this event. The event primarily exists to facilitate * a transition of some legacy code. + * + * Event name: 'civi.token.render' */ class TokenRenderEvent extends TokenEvent { diff --git a/Civi/Token/Event/TokenValueEvent.php b/Civi/Token/Event/TokenValueEvent.php index 5201ecdd6505..c9a251ccc752 100644 --- a/Civi/Token/Event/TokenValueEvent.php +++ b/Civi/Token/Event/TokenValueEvent.php @@ -32,6 +32,7 @@ * } * @encode * + * Event name: 'civi.token.eval' */ class TokenValueEvent extends TokenEvent { diff --git a/Civi/Token/Events.php b/Civi/Token/Events.php index 7c7869ef0951..4f17c09f5441 100644 --- a/Civi/Token/Events.php +++ b/Civi/Token/Events.php @@ -4,28 +4,20 @@ class Events { /** - * Create a list of supported tokens. - * * @see \Civi\Token\Event\TokenRegisterEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const TOKEN_REGISTER = 'civi.token.list'; /** - * Create a list of supported tokens. - * * @see \Civi\Token\Event\TokenValueEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const TOKEN_EVALUATE = 'civi.token.eval'; /** - * Perform post-processing on a rendered message. - * - * WARNING: It is difficult to develop robust, - * secure code using this stage. However, we need - * to support it during a transitional period - * while the token logic is reorganized. - * * @see \Civi\Token\Event\TokenRenderEvent + * @deprecated - You may simply use the event name directly. dev/core#1744 */ const TOKEN_RENDER = 'civi.token.render'; diff --git a/Civi/Token/TokenCompatSubscriber.php b/Civi/Token/TokenCompatSubscriber.php index ae8a55f61665..c4a07af5595c 100644 --- a/Civi/Token/TokenCompatSubscriber.php +++ b/Civi/Token/TokenCompatSubscriber.php @@ -25,8 +25,8 @@ class TokenCompatSubscriber implements EventSubscriberInterface { */ public static function getSubscribedEvents() { return [ - Events::TOKEN_EVALUATE => 'onEvaluate', - Events::TOKEN_RENDER => 'onRender', + 'civi.token.eval' => 'onEvaluate', + 'civi.token.render' => 'onRender', ]; } diff --git a/Civi/Token/TokenProcessor.php b/Civi/Token/TokenProcessor.php index e27705300d9d..0d1ff138db50 100644 --- a/Civi/Token/TokenProcessor.php +++ b/Civi/Token/TokenProcessor.php @@ -306,7 +306,7 @@ public function getTokens() { if ($this->tokens === NULL) { $this->tokens = []; $event = new TokenRegisterEvent($this, ['entity' => 'undefined']); - $this->dispatcher->dispatch(Events::TOKEN_REGISTER, $event); + $this->dispatcher->dispatch('civi.token.list', $event); } return $this->tokens; } @@ -332,7 +332,7 @@ public function listTokens() { */ public function evaluate() { $event = new TokenValueEvent($this); - $this->dispatcher->dispatch(Events::TOKEN_EVALUATE, $event); + $this->dispatcher->dispatch('civi.token.eval', $event); return $this; } @@ -371,7 +371,7 @@ public function render($name, $row) { $event->context = $row->context; $event->row = $row; $event->string = strtr($message['string'], $filteredTokens); - $this->dispatcher->dispatch(Events::TOKEN_RENDER, $event); + $this->dispatcher->dispatch('civi.token.render', $event); return $event->string; } diff --git a/tests/phpunit/Civi/API/Event/PrepareEventTest.php b/tests/phpunit/Civi/API/Event/PrepareEventTest.php index 258a7bf64212..ce5516c98b28 100644 --- a/tests/phpunit/Civi/API/Event/PrepareEventTest.php +++ b/tests/phpunit/Civi/API/Event/PrepareEventTest.php @@ -2,7 +2,6 @@ namespace Civi\API\Event; use Symfony\Component\EventDispatcher\EventDispatcher; -use Civi\API\Events; use Civi\API\Kernel; /** @@ -45,7 +44,7 @@ public function getPrepareExamples() { * @dataProvider getPrepareExamples */ public function testOnPrepare($onPrepare, $inputApiCall, $expectResult) { - $this->dispatcher->addListener(Events::PREPARE, [$this, $onPrepare]); + $this->dispatcher->addListener('civi.api.prepare', [$this, $onPrepare]); $this->kernel->registerApiProvider($this->createWidgetFrobnicateProvider()); $result = call_user_func_array([$this->kernel, 'runSafe'], $inputApiCall); $this->assertEquals($expectResult, $result['values']); diff --git a/tests/phpunit/Civi/API/KernelTest.php b/tests/phpunit/Civi/API/KernelTest.php index 6d8829b01d65..32ef294712ce 100644 --- a/tests/phpunit/Civi/API/KernelTest.php +++ b/tests/phpunit/Civi/API/KernelTest.php @@ -39,10 +39,10 @@ public function testNormalEvents() { ]); $expectedEventSequence = [ - ['name' => Events::RESOLVE, 'class' => 'Civi\API\Event\ResolveEvent'], - ['name' => Events::AUTHORIZE, 'class' => 'Civi\API\Event\AuthorizeEvent'], - ['name' => Events::PREPARE, 'class' => 'Civi\API\Event\PrepareEvent'], - ['name' => Events::RESPOND, 'class' => 'Civi\API\Event\RespondEvent'], + ['name' => 'civi.api.resolve', 'class' => 'Civi\API\Event\ResolveEvent'], + ['name' => 'civi.api.authorize', 'class' => 'Civi\API\Event\AuthorizeEvent'], + ['name' => 'civi.api.prepare', 'class' => 'Civi\API\Event\PrepareEvent'], + ['name' => 'civi.api.respond', 'class' => 'Civi\API\Event\RespondEvent'], ]; $this->assertEquals($expectedEventSequence, $this->actualEventSequence); $this->assertEquals('frob', $result['values'][98]); @@ -50,10 +50,10 @@ public function testNormalEvents() { public function testResolveException() { $test = $this; - $this->dispatcher->addListener(Events::RESOLVE, function () { + $this->dispatcher->addListener('civi.api.resolve', function () { throw new \API_Exception('Oh My God', 'omg', ['the' => 'badzes']); }, Events::W_EARLY); - $this->dispatcher->addListener(Events::EXCEPTION, function (\Civi\API\Event\ExceptionEvent $event) use ($test) { + $this->dispatcher->addListener('civi.api.exception', function (\Civi\API\Event\ExceptionEvent $event) use ($test) { $test->assertEquals('Oh My God', $event->getException()->getMessage()); }); @@ -63,8 +63,8 @@ public function testResolveException() { ]); $expectedEventSequence = [ - ['name' => Events::RESOLVE, 'class' => 'Civi\API\Event\ResolveEvent'], - ['name' => Events::EXCEPTION, 'class' => 'Civi\API\Event\ExceptionEvent'], + ['name' => 'civi.api.resolve', 'class' => 'Civi\API\Event\ResolveEvent'], + ['name' => 'civi.api.exception', 'class' => 'Civi\API\Event\ExceptionEvent'], ]; $this->assertEquals($expectedEventSequence, $this->actualEventSequence); $this->assertEquals('Oh My God', $result['error_message']); diff --git a/tests/phpunit/Civi/Token/TokenProcessorTest.php b/tests/phpunit/Civi/Token/TokenProcessorTest.php index bbef30cfe203..f4e667a16615 100644 --- a/tests/phpunit/Civi/Token/TokenProcessorTest.php +++ b/tests/phpunit/Civi/Token/TokenProcessorTest.php @@ -22,8 +22,8 @@ protected function setUp() { $this->useTransaction(TRUE); parent::setUp(); $this->dispatcher = new EventDispatcher(); - $this->dispatcher->addListener(Events::TOKEN_REGISTER, [$this, 'onListTokens']); - $this->dispatcher->addListener(Events::TOKEN_EVALUATE, [$this, 'onEvalTokens']); + $this->dispatcher->addListener('civi.token.list', [$this, 'onListTokens']); + $this->dispatcher->addListener('civi.token.eval', [$this, 'onEvalTokens']); $this->counts = [ 'onListTokens' => 0, 'onEvalTokens' => 0,