Commit | Line | Data |
---|---|---|
132ec342 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
41498ac5 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
132ec342 | 5 | | | |
41498ac5 TO |
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 | | |
132ec342 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
132ec342 TO |
11 | namespace Civi\API; |
12 | ||
13 | /** | |
14 | * The API kernel dispatches a series of events while processing each API request. | |
787604ff | 15 | * For a successful API request, the sequence is RESOLVE => AUTHORIZE => PREPARE => RESPOND. |
132ec342 TO |
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 | |
855d0fe0 | 20 | * a priority to their subscription (such as W_EARLY, W_MIDDLE, or W_LATE). |
132ec342 TO |
21 | */ |
22 | class Events { | |
23 | ||
24 | /** | |
132ec342 | 25 | * @see AuthorizeEvent |
39b870b8 | 26 | * @deprecated - You may simply use the event name directly. dev/core#1744 |
132ec342 | 27 | */ |
f247addc | 28 | const AUTHORIZE = 'civi.api.authorize'; |
132ec342 | 29 | |
787604ff | 30 | /** |
787604ff | 31 | * @see ResolveEvent |
39b870b8 | 32 | * @deprecated - You may simply use the event name directly. dev/core#1744 |
787604ff | 33 | */ |
f247addc | 34 | const RESOLVE = 'civi.api.resolve'; |
787604ff | 35 | |
132ec342 | 36 | /** |
132ec342 | 37 | * @see PrepareEvent |
39b870b8 | 38 | * @deprecated - You may simply use the event name directly. dev/core#1744 |
132ec342 | 39 | */ |
f247addc | 40 | const PREPARE = 'civi.api.prepare'; |
132ec342 TO |
41 | |
42 | /** | |
43 | * Apply post-execution logic | |
44 | * | |
45 | * @see RespondEvent | |
39b870b8 | 46 | * @deprecated - You may simply use the event name directly. dev/core#1744 |
132ec342 | 47 | */ |
f247addc | 48 | const RESPOND = 'civi.api.respond'; |
132ec342 TO |
49 | |
50 | /** | |
fe482240 | 51 | * Handle any exceptions. |
132ec342 TO |
52 | * |
53 | * @see ExceptionEvent | |
39b870b8 | 54 | * @deprecated - You may simply use the event name directly. dev/core#1744 |
132ec342 | 55 | */ |
f247addc | 56 | const EXCEPTION = 'civi.api.exception'; |
132ec342 TO |
57 | |
58 | /** | |
855d0fe0 | 59 | * Priority - Higher numbers execute earlier |
132ec342 TO |
60 | */ |
61 | const W_EARLY = 100; | |
62 | ||
63 | /** | |
855d0fe0 | 64 | * Priority - Middle |
132ec342 TO |
65 | */ |
66 | const W_MIDDLE = 0; | |
67 | ||
68 | /** | |
855d0fe0 | 69 | * Priority - Lower numbers execute later |
132ec342 TO |
70 | */ |
71 | const W_LATE = -100; | |
70265090 TO |
72 | |
73 | /** | |
74 | * @return array<string> | |
75 | */ | |
76 | public static function allEvents() { | |
c64f69d9 | 77 | return [ |
39b870b8 TO |
78 | 'civi.api.authorize', |
79 | 'civi.api.exception', | |
80 | 'civi.api.prepare', | |
81 | 'civi.api.resolve', | |
82 | 'civi.api.respond', | |
c64f69d9 | 83 | ]; |
70265090 | 84 | } |
96025800 | 85 | |
0d0031a0 TO |
86 | /** |
87 | * @param \Civi\Core\Event\GenericHookEvent $e | |
47e7c2f8 | 88 | * @see \CRM_Utils_Hook::eventDefs |
0d0031a0 TO |
89 | */ |
90 | public static function hookEventDefs($e) { | |
39b870b8 TO |
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'); | |
0d0031a0 TO |
96 | } |
97 | ||
132ec342 | 98 | } |