Commit | Line | Data |
---|---|---|
132ec342 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
132ec342 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
132ec342 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
132ec342 TO |
27 | namespace Civi\API; |
28 | ||
29 | /** | |
30 | * The API kernel dispatches a series of events while processing each API request. | |
787604ff | 31 | * For a successful API request, the sequence is RESOLVE => AUTHORIZE => PREPARE => RESPOND. |
132ec342 TO |
32 | * If an exception arises in any stage, then the sequence is aborted and the EXCEPTION |
33 | * event is dispatched. | |
34 | * | |
35 | * Event subscribers which are concerned about the order of execution should assign | |
855d0fe0 | 36 | * a priority to their subscription (such as W_EARLY, W_MIDDLE, or W_LATE). |
132ec342 TO |
37 | */ |
38 | class Events { | |
39 | ||
40 | /** | |
41 | * Determine whether the API request is allowed for the current user. | |
8882ff5c TO |
42 | * For successful execution, at least one listener must invoke |
43 | * $event->authorize(). | |
132ec342 TO |
44 | * |
45 | * @see AuthorizeEvent | |
46 | */ | |
f247addc | 47 | const AUTHORIZE = 'civi.api.authorize'; |
132ec342 | 48 | |
787604ff TO |
49 | /** |
50 | * Determine which API provider executes the given request. For successful | |
8882ff5c TO |
51 | * execution, at least one listener must invoke |
52 | * $event->setProvider($provider). | |
787604ff TO |
53 | * |
54 | * @see ResolveEvent | |
55 | */ | |
f247addc | 56 | const RESOLVE = 'civi.api.resolve'; |
787604ff | 57 | |
132ec342 TO |
58 | /** |
59 | * Apply pre-execution logic | |
60 | * | |
61 | * @see PrepareEvent | |
62 | */ | |
f247addc | 63 | const PREPARE = 'civi.api.prepare'; |
132ec342 TO |
64 | |
65 | /** | |
66 | * Apply post-execution logic | |
67 | * | |
68 | * @see RespondEvent | |
69 | */ | |
f247addc | 70 | const RESPOND = 'civi.api.respond'; |
132ec342 TO |
71 | |
72 | /** | |
fe482240 | 73 | * Handle any exceptions. |
132ec342 TO |
74 | * |
75 | * @see ExceptionEvent | |
76 | */ | |
f247addc | 77 | const EXCEPTION = 'civi.api.exception'; |
132ec342 TO |
78 | |
79 | /** | |
855d0fe0 | 80 | * Priority - Higher numbers execute earlier |
132ec342 TO |
81 | */ |
82 | const W_EARLY = 100; | |
83 | ||
84 | /** | |
855d0fe0 | 85 | * Priority - Middle |
132ec342 TO |
86 | */ |
87 | const W_MIDDLE = 0; | |
88 | ||
89 | /** | |
855d0fe0 | 90 | * Priority - Lower numbers execute later |
132ec342 TO |
91 | */ |
92 | const W_LATE = -100; | |
70265090 TO |
93 | |
94 | /** | |
95 | * @return array<string> | |
96 | */ | |
97 | public static function allEvents() { | |
c64f69d9 | 98 | return [ |
70265090 TO |
99 | self::AUTHORIZE, |
100 | self::EXCEPTION, | |
101 | self::PREPARE, | |
102 | self::RESOLVE, | |
103 | self::RESPOND, | |
c64f69d9 | 104 | ]; |
70265090 | 105 | } |
96025800 | 106 | |
0d0031a0 TO |
107 | /** |
108 | * @param \Civi\Core\Event\GenericHookEvent $e | |
47e7c2f8 | 109 | * @see \CRM_Utils_Hook::eventDefs |
0d0031a0 TO |
110 | */ |
111 | public static function hookEventDefs($e) { | |
112 | $e->inspector->addEventClass(self::AUTHORIZE, 'Civi\API\Event\AuthorizeEvent'); | |
113 | $e->inspector->addEventClass(self::EXCEPTION, 'Civi\API\Event\ExceptionEvent'); | |
114 | $e->inspector->addEventClass(self::PREPARE, 'Civi\API\Event\PrepareEvent'); | |
115 | $e->inspector->addEventClass(self::RESOLVE, 'Civi\API\Event\ResolveEvent'); | |
116 | $e->inspector->addEventClass(self::RESPOND, 'Civi\API\Event\RespondEvent'); | |
117 | } | |
118 | ||
132ec342 | 119 | } |