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 | /** | |
25 | * Determine whether the API request is allowed for the current user. | |
8882ff5c TO |
26 | * For successful execution, at least one listener must invoke |
27 | * $event->authorize(). | |
132ec342 TO |
28 | * |
29 | * @see AuthorizeEvent | |
30 | */ | |
f247addc | 31 | const AUTHORIZE = 'civi.api.authorize'; |
132ec342 | 32 | |
787604ff TO |
33 | /** |
34 | * Determine which API provider executes the given request. For successful | |
8882ff5c TO |
35 | * execution, at least one listener must invoke |
36 | * $event->setProvider($provider). | |
787604ff TO |
37 | * |
38 | * @see ResolveEvent | |
39 | */ | |
f247addc | 40 | const RESOLVE = 'civi.api.resolve'; |
787604ff | 41 | |
132ec342 TO |
42 | /** |
43 | * Apply pre-execution logic | |
44 | * | |
45 | * @see PrepareEvent | |
46 | */ | |
f247addc | 47 | const PREPARE = 'civi.api.prepare'; |
132ec342 TO |
48 | |
49 | /** | |
50 | * Apply post-execution logic | |
51 | * | |
52 | * @see RespondEvent | |
53 | */ | |
f247addc | 54 | const RESPOND = 'civi.api.respond'; |
132ec342 TO |
55 | |
56 | /** | |
fe482240 | 57 | * Handle any exceptions. |
132ec342 TO |
58 | * |
59 | * @see ExceptionEvent | |
60 | */ | |
f247addc | 61 | const EXCEPTION = 'civi.api.exception'; |
132ec342 TO |
62 | |
63 | /** | |
855d0fe0 | 64 | * Priority - Higher numbers execute earlier |
132ec342 TO |
65 | */ |
66 | const W_EARLY = 100; | |
67 | ||
68 | /** | |
855d0fe0 | 69 | * Priority - Middle |
132ec342 TO |
70 | */ |
71 | const W_MIDDLE = 0; | |
72 | ||
73 | /** | |
855d0fe0 | 74 | * Priority - Lower numbers execute later |
132ec342 TO |
75 | */ |
76 | const W_LATE = -100; | |
70265090 TO |
77 | |
78 | /** | |
79 | * @return array<string> | |
80 | */ | |
81 | public static function allEvents() { | |
c64f69d9 | 82 | return [ |
70265090 TO |
83 | self::AUTHORIZE, |
84 | self::EXCEPTION, | |
85 | self::PREPARE, | |
86 | self::RESOLVE, | |
87 | self::RESPOND, | |
c64f69d9 | 88 | ]; |
70265090 | 89 | } |
96025800 | 90 | |
0d0031a0 TO |
91 | /** |
92 | * @param \Civi\Core\Event\GenericHookEvent $e | |
47e7c2f8 | 93 | * @see \CRM_Utils_Hook::eventDefs |
0d0031a0 TO |
94 | */ |
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'); | |
101 | } | |
102 | ||
132ec342 | 103 | } |