Skip to content

Commit

Permalink
Merge pull request #17240 from totten/master-event-names
Browse files Browse the repository at this point in the history
(REF) dev/core#1744 - Cleanup event naming
  • Loading branch information
mattwire authored May 6, 2020
2 parents 6e32198 + 39b870b commit ccc8a89
Show file tree
Hide file tree
Showing 40 changed files with 121 additions and 107 deletions.
4 changes: 2 additions & 2 deletions CRM/Core/BAO/ActionSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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)
);

Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions Civi/API/Event/AuthorizeEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down
5 changes: 3 additions & 2 deletions Civi/API/Event/ExceptionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
4 changes: 4 additions & 0 deletions Civi/API/Event/PrepareEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
6 changes: 6 additions & 0 deletions Civi/API/Event/ResolveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
4 changes: 4 additions & 0 deletions Civi/API/Event/RespondEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down
35 changes: 15 additions & 20 deletions Civi/API/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,36 @@
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';

/**
* Apply post-execution logic
*
* @see RespondEvent
* @deprecated - You may simply use the event name directly. dev/core#1744
*/
const RESPOND = 'civi.api.respond';

/**
* Handle any exceptions.
*
* @see ExceptionEvent
* @deprecated - You may simply use the event name directly. dev/core#1744
*/
const EXCEPTION = 'civi.api.exception';

Expand All @@ -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',
];
}

Expand All @@ -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');
}

}
10 changes: 5 additions & 5 deletions Civi/API/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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!)");
Expand All @@ -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");
}
Expand All @@ -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()];
}

Expand All @@ -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();
}

Expand Down
4 changes: 2 additions & 2 deletions Civi/API/Provider/AdhocProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
],
];
Expand Down
2 changes: 1 addition & 1 deletion Civi/API/Provider/MagicFunctionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterfa
*/
public static function getSubscribedEvents() {
return [
Events::RESOLVE => [
'civi.api.resolve' => [
['onApiResolve', Events::W_MIDDLE],
],
];
Expand Down
4 changes: 2 additions & 2 deletions Civi/API/Provider/ReflectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
],
Expand Down
4 changes: 2 additions & 2 deletions Civi/API/Provider/StaticProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
],
];
Expand Down
2 changes: 1 addition & 1 deletion Civi/API/Subscriber/APIv3SchemaAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
],
Expand Down
2 changes: 1 addition & 1 deletion Civi/API/Subscriber/ChainSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
];
}

Expand Down
5 changes: 2 additions & 3 deletions Civi/API/Subscriber/DebugSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Civi\API\Subscriber;

use Civi\API\Events;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
Expand All @@ -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],
];
}

Expand Down
2 changes: 1 addition & 1 deletion Civi/API/Subscriber/DynamicFKAuthorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DynamicFKAuthorization implements EventSubscriberInterface {
*/
public static function getSubscribedEvents() {
return [
Events::AUTHORIZE => [
'civi.api.authorize' => [
['onApiAuthorize', Events::W_EARLY],
],
];
Expand Down
4 changes: 2 additions & 2 deletions Civi/API/Subscriber/I18nSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
];
}

Expand Down
2 changes: 1 addition & 1 deletion Civi/API/Subscriber/PermissionCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PermissionCheck implements EventSubscriberInterface {
*/
public static function getSubscribedEvents() {
return [
Events::AUTHORIZE => [
'civi.api.authorize' => [
['onApiAuthorize', Events::W_LATE],
],
];
Expand Down
6 changes: 3 additions & 3 deletions Civi/API/Subscriber/TransactionSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
];
}

Expand Down
4 changes: 2 additions & 2 deletions Civi/API/Subscriber/WhitelistSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
];
}

Expand Down
4 changes: 2 additions & 2 deletions Civi/API/Subscriber/WrapperAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
];
}

Expand Down
2 changes: 2 additions & 0 deletions Civi/ActionSchedule/Event/MailingQueryEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
2 changes: 2 additions & 0 deletions Civi/ActionSchedule/Event/MappingRegisterEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* @package Civi\ActionSchedule\Event
*
* Register any available mappings.
*
* Event name: 'civi.actionSchedule.getMappings'
*/
class MappingRegisterEvent extends Event {

Expand Down
Loading

0 comments on commit ccc8a89

Please sign in to comment.