Total Complexity | 8 |
Total Lines | 98 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
12 | class Event implements StoppableEventInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $name; |
||
18 | |||
19 | /** |
||
20 | * @var object|null |
||
21 | */ |
||
22 | protected $subject; |
||
23 | |||
24 | /** |
||
25 | * @var mixed |
||
26 | */ |
||
27 | protected $payload; |
||
28 | |||
29 | /** |
||
30 | * @var bool |
||
31 | */ |
||
32 | protected $propagationStopped = false; |
||
33 | |||
34 | /** |
||
35 | * Event constructor. |
||
36 | * |
||
37 | * @param string $name |
||
38 | * @param object|null $subject |
||
39 | * @param mixed $payload |
||
40 | */ |
||
41 | 4 | public function __construct(string $name, ?object $subject = null, $payload = null) |
|
42 | { |
||
43 | 4 | if (strpos($name, '*') !== false) { |
|
44 | 1 | throw new \InvalidArgumentException("Invalid event name '$name': illegal character '*'"); |
|
45 | } |
||
46 | |||
47 | 3 | $this->name = $name; |
|
48 | 3 | $this->subject = $subject; |
|
49 | 3 | $this->payload = $payload; |
|
50 | 3 | } |
|
51 | |||
52 | |||
53 | /** |
||
54 | * Get the event name |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | 1 | public function getName(): string |
|
59 | { |
||
60 | 1 | return $this->name; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * Get the event subject (typically an object) |
||
65 | * |
||
66 | * @return object|null |
||
67 | */ |
||
68 | 1 | public function getSubject(): ?object |
|
69 | { |
||
70 | 1 | return $this->subject; |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * Change the event payload. |
||
75 | * |
||
76 | * @param mixed $payload |
||
77 | */ |
||
78 | 1 | public function setPayload($payload): void |
|
79 | { |
||
80 | 1 | $this->payload = $payload; |
|
81 | 1 | } |
|
82 | |||
83 | /** |
||
84 | * Get the event payload. |
||
85 | * |
||
86 | * @return mixed |
||
87 | */ |
||
88 | 2 | public function getPayload() |
|
89 | { |
||
90 | 2 | return $this->payload; |
|
91 | } |
||
92 | |||
93 | |||
94 | /** |
||
95 | * Do call subsequent event listeners. |
||
96 | */ |
||
97 | 1 | public function stopPropagation(): void |
|
98 | { |
||
99 | 1 | $this->propagationStopped = true; |
|
100 | 1 | } |
|
101 | |||
102 | /** |
||
103 | * Is propagation stopped? |
||
104 | * |
||
105 | * @return bool |
||
106 | */ |
||
107 | 1 | public function isPropagationStopped(): bool |
|
110 | } |
||
111 | } |
||
112 |