3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
14 * The API kernel dispatches a series of events while processing each API request.
15 * For a successful API request, the sequence is RESOLVE => AUTHORIZE => PREPARE => RESPOND.
16 * If an exception arises in any stage, then the sequence is aborted and the EXCEPTION
17 * event is dispatched.
19 * Event subscribers which are concerned about the order of execution should assign
20 * a priority to their subscription (such as W_EARLY, W_MIDDLE, or W_LATE).
25 * Determine whether the API request is allowed for the current user.
26 * For successful execution, at least one listener must invoke
27 * $event->authorize().
31 const AUTHORIZE
= 'civi.api.authorize';
34 * Determine which API provider executes the given request. For successful
35 * execution, at least one listener must invoke
36 * $event->setProvider($provider).
40 const RESOLVE
= 'civi.api.resolve';
43 * Apply pre-execution logic
47 const PREPARE
= 'civi.api.prepare';
50 * Apply post-execution logic
54 const RESPOND
= 'civi.api.respond';
57 * Handle any exceptions.
61 const EXCEPTION
= 'civi.api.exception';
64 * Priority - Higher numbers execute earlier
74 * Priority - Lower numbers execute later
79 * @return array<string>
81 public static function allEvents() {
92 * @param \Civi\Core\Event\GenericHookEvent $e
93 * @see \CRM_Utils_Hook::eventDefs
95 public static function hookEventDefs($e) {
96 $e->inspector
->addEventClass(self
::AUTHORIZE
, 'Civi\API\Event\AuthorizeEvent');
97 $e->inspector
->addEventClass(self
::EXCEPTION
, 'Civi\API\Event\ExceptionEvent');
98 $e->inspector
->addEventClass(self
::PREPARE
, 'Civi\API\Event\PrepareEvent');
99 $e->inspector
->addEventClass(self
::RESOLVE
, 'Civi\API\Event\ResolveEvent');
100 $e->inspector
->addEventClass(self
::RESPOND
, 'Civi\API\Event\RespondEvent');