Merge pull request #17836 from seamuslee001/dev_core_1874
[civicrm-core.git] / Civi / API / Events.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11 namespace Civi\API;
12
13 /**
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.
18 *
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).
21 */
22 class Events {
23
24 /**
25 * @see AuthorizeEvent
26 * @deprecated - You may simply use the event name directly. dev/core#1744
27 */
28 const AUTHORIZE = 'civi.api.authorize';
29
30 /**
31 * @see ResolveEvent
32 * @deprecated - You may simply use the event name directly. dev/core#1744
33 */
34 const RESOLVE = 'civi.api.resolve';
35
36 /**
37 * @see PrepareEvent
38 * @deprecated - You may simply use the event name directly. dev/core#1744
39 */
40 const PREPARE = 'civi.api.prepare';
41
42 /**
43 * Apply post-execution logic
44 *
45 * @see RespondEvent
46 * @deprecated - You may simply use the event name directly. dev/core#1744
47 */
48 const RESPOND = 'civi.api.respond';
49
50 /**
51 * Handle any exceptions.
52 *
53 * @see ExceptionEvent
54 * @deprecated - You may simply use the event name directly. dev/core#1744
55 */
56 const EXCEPTION = 'civi.api.exception';
57
58 /**
59 * Priority - Higher numbers execute earlier
60 */
61 const W_EARLY = 100;
62
63 /**
64 * Priority - Middle
65 */
66 const W_MIDDLE = 0;
67
68 /**
69 * Priority - Lower numbers execute later
70 */
71 const W_LATE = -100;
72
73 /**
74 * @return array<string>
75 */
76 public static function allEvents() {
77 return [
78 'civi.api.authorize',
79 'civi.api.exception',
80 'civi.api.prepare',
81 'civi.api.resolve',
82 'civi.api.respond',
83 ];
84 }
85
86 /**
87 * @param \Civi\Core\Event\GenericHookEvent $e
88 * @see \CRM_Utils_Hook::eventDefs
89 */
90 public static function hookEventDefs($e) {
91 $e->inspector->addEventClass('civi.api.authorize', 'Civi\API\Event\AuthorizeEvent');
92 $e->inspector->addEventClass('civi.api.exception', 'Civi\API\Event\ExceptionEvent');
93 $e->inspector->addEventClass('civi.api.prepare', 'Civi\API\Event\PrepareEvent');
94 $e->inspector->addEventClass('civi.api.resolve', 'Civi\API\Event\ResolveEvent');
95 $e->inspector->addEventClass('civi.api.respond', 'Civi\API\Event\RespondEvent');
96 }
97
98 }