Completed
Push — master ( 33372a...46be78 )
by J.D.
03:04
created

WordPoints_Hook_Firer   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5
Metric Value
wmc 9
lcom 0
cbo 5
dl 0
loc 73
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get_slug() 0 3 1
C do_event() 0 44 7
1
<?php
2
3
/**
4
 * Hook firer class.
5
 *
6
 * @package wordpoints-hooks-api
7
 * @since   1.0.0
8
 */
9
10
/**
11
 * Fires a hook event.
12
 *
13
 * @since 1.0.0
14
 */
15
class WordPoints_Hook_Firer implements WordPoints_Hook_FirerI {
16
17
	/**
18
	 * The firer slug.
19
	 *
20
	 * @since 1.0.0
21
	 *
22
	 * @var string
23
	 */
24
	protected $slug;
25
26
	/**
27
	 * @since 1.0.0
28
	 */
29
	public function __construct( $slug ) {
30
		$this->slug = $slug;
31
	}
32
33
	/**
34
	 * @since 1.0.0
35
	 */
36
	public function get_slug() {
37
		return $this->slug;
38
	}
39
40
	/**
41
	 * @since 1.0.0
42
	 */
43
	public function do_event( $event_slug, WordPoints_Hook_Event_Args $event_args ) {
44
45
		$hooks = wordpoints_hooks();
46
47
		/** @var WordPoints_Hook_Reactor $reactor */
48
		foreach ( $hooks->reactors->get_all() as $reactor ) {
49
50
			foreach ( $reactor->get_all_reactions_to_event( $event_slug ) as $reaction ) {
51
52
				$validator = new WordPoints_Hook_Reaction_Validator(
53
					$reaction
54
					, $reactor
55
					, true
56
				);
57
58
				$validator->validate();
59
60
				if ( $validator->had_errors() ) {
61
					continue;
62
				}
63
64
				unset( $validator );
65
66
				$fire = new WordPoints_Hook_Fire( $this, $event_args, $reaction );
67
68
				/** @var WordPoints_Hook_Extension[] $extensions */
69
				$extensions = $hooks->extensions->get_all();
70
71
				foreach ( $extensions as $extension ) {
72
					if ( ! $extension->should_hit( $fire ) ) {
73
						continue 2;
74
					}
75
				}
76
77
				$fire->hit();
78
79
				$reactor->hit( $fire );
80
81
				foreach ( $extensions as $extension ) {
82
					$extension->after_hit( $fire );
83
				}
84
			}
85
		}
86
	}
87
}
88
89
// EOF
90