Commit | Line | Data |
---|---|---|
132ec342 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.4 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
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 | |
36 | * a weight to their subscription (such as W_EARLY, W_MIDDLE, or W_LATE). | |
37 | */ | |
38 | class Events { | |
39 | ||
40 | /** | |
41 | * Determine whether the API request is allowed for the current user. | |
42 | * For successful execution, at least one listener must invoke $event->authorize(). | |
43 | * | |
44 | * @see AuthorizeEvent | |
45 | */ | |
46 | const AUTHORIZE = 'api.authorize'; | |
47 | ||
787604ff TO |
48 | /** |
49 | * Determine which API provider executes the given request. For successful | |
50 | * execution, at least one listener must invoke $event->setProvider($provider). | |
51 | * | |
52 | * @see ResolveEvent | |
53 | */ | |
54 | const RESOLVE = 'api.resolve'; | |
55 | ||
132ec342 TO |
56 | /** |
57 | * Apply pre-execution logic | |
58 | * | |
59 | * @see PrepareEvent | |
60 | */ | |
61 | const PREPARE = 'api.prepare'; | |
62 | ||
63 | /** | |
64 | * Apply post-execution logic | |
65 | * | |
66 | * @see RespondEvent | |
67 | */ | |
68 | const RESPOND = 'api.respond'; | |
69 | ||
70 | /** | |
71 | * Handle any exceptions | |
72 | * | |
73 | * @see ExceptionEvent | |
74 | */ | |
75 | const EXCEPTION = 'api.exception'; | |
76 | ||
77 | /** | |
78 | * Weight - Early | |
79 | */ | |
80 | const W_EARLY = 100; | |
81 | ||
82 | /** | |
83 | * Weight - Middle | |
84 | */ | |
85 | const W_MIDDLE = 0; | |
86 | ||
87 | /** | |
88 | * Weight - Late | |
89 | */ | |
90 | const W_LATE = -100; | |
70265090 TO |
91 | |
92 | /** | |
93 | * @return array<string> | |
94 | */ | |
95 | public static function allEvents() { | |
96 | return array( | |
97 | self::AUTHORIZE, | |
98 | self::EXCEPTION, | |
99 | self::PREPARE, | |
100 | self::RESOLVE, | |
101 | self::RESPOND, | |
102 | ); | |
103 | } | |
132ec342 | 104 | } |