1 | <?php |
||
31 | class WordPoints_Hook_Router { |
||
32 | |||
33 | /** |
||
34 | * The actions registry object. |
||
35 | * |
||
36 | * @since 1.0.0 |
||
37 | * |
||
38 | * @var WordPoints_Hook_Actions |
||
39 | */ |
||
40 | protected $actions; |
||
41 | |||
42 | /** |
||
43 | * The events registry object. |
||
44 | * |
||
45 | * @since 1.0.0 |
||
46 | * |
||
47 | * @var WordPoints_Hook_Events |
||
48 | */ |
||
49 | protected $events; |
||
50 | |||
51 | /** |
||
52 | * The actions, indexed by WordPress action/filter hooks. |
||
53 | * |
||
54 | * The indexes are of this format: "$action_or_filter_name,$priority". |
||
55 | * |
||
56 | * @since 1.0.0 |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | protected $action_index = array(); |
||
61 | |||
62 | /** |
||
63 | * The events, indexed by action slug and action type. |
||
64 | * |
||
65 | * @since 1.0.0 |
||
66 | * |
||
67 | * @var array |
||
68 | */ |
||
69 | protected $event_index = array(); |
||
70 | |||
71 | /** |
||
72 | * @since 1.0.0 |
||
73 | */ |
||
74 | public function __call( $name, $args ) { |
||
86 | |||
87 | /** |
||
88 | * Routes a WordPress action to WordPoints hook actions, and fires their events. |
||
89 | * |
||
90 | * @since 1.0.0 |
||
91 | * |
||
92 | * @param string $name The action ID. This is not the slug of a hook action, but |
||
93 | * rather a unique ID for the WordPress action based on the |
||
94 | * action name and the priority. |
||
95 | * @param array $args The args the action was fired with. |
||
96 | */ |
||
97 | protected function route_action( $name, $args ) { |
||
151 | |||
152 | /** |
||
153 | * Fire an event at each of the reactions. |
||
154 | * |
||
155 | * @since 1.0.0 |
||
156 | * |
||
157 | * @param string $action_type The type of action triggering |
||
158 | * this fire of this event. |
||
159 | * @param string $event_slug The slug of the event. |
||
160 | * @param WordPoints_Hook_Event_Args $event_args The event args. |
||
161 | */ |
||
162 | public function fire_event( |
||
214 | |||
215 | /** |
||
216 | * Register an action with the router. |
||
217 | * |
||
218 | * The arg number will be automatically determined based on $data['arg_index'] |
||
219 | * and $data['requirements']. So in most cases $arg_number may be omitted. |
||
220 | * |
||
221 | * @since 1.0.0 |
||
222 | * |
||
223 | * @param string $slug The slug of the action. |
||
224 | * @param array $args { |
||
225 | * Other arguments. |
||
226 | * |
||
227 | * @type string $action The name of the WordPress action for this hook action. |
||
228 | * @type int $priority The priority for the WordPress action. Default: 10. |
||
229 | * @type int $arg_number The number of args the action object expects. Default: 1. |
||
230 | * @type array $data { |
||
231 | * Args that will be passed to the action object's constructor. |
||
232 | * |
||
233 | * @type int[] $arg_index List of args (starting from 0), indexed by slug. |
||
234 | * @type array $requirements List of requirements, indexed by arg index (from 0). |
||
235 | * } |
||
236 | * } |
||
237 | */ |
||
238 | public function add_action( $slug, array $args ) { |
||
289 | |||
290 | /** |
||
291 | * Deregister an action with the router. |
||
292 | * |
||
293 | * @since 1.0.0 |
||
294 | * |
||
295 | * @param string $slug The action slug. |
||
296 | */ |
||
297 | public function remove_action( $slug ) { |
||
315 | |||
316 | /** |
||
317 | * Hook an event to an action. |
||
318 | * |
||
319 | * @since 1.0.0 |
||
320 | * |
||
321 | * @param string $event_slug The slug of the event. |
||
322 | * @param string $action_slug The slug of the action. |
||
323 | * @param string $action_type The type of action. Default is 'fire'. |
||
324 | */ |
||
325 | public function add_event_to_action( $event_slug, $action_slug, $action_type = 'fire' ) { |
||
328 | |||
329 | /** |
||
330 | * Unhook an event from an action. |
||
331 | * |
||
332 | * @since 1.0.0 |
||
333 | * |
||
334 | * @param string $event_slug The slug of the event. |
||
335 | * @param string $action_slug The slug of the action. |
||
336 | * @param string $action_type The type of action. Default is 'fire'. |
||
337 | */ |
||
338 | public function remove_event_from_action( $event_slug, $action_slug, $action_type = 'fire' ) { |
||
341 | } |
||
342 | |||
344 |