1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the slince/event-dispatcher package. |
5
|
|
|
* |
6
|
|
|
* (c) Slince <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Slince\EventDispatcher; |
13
|
|
|
|
14
|
|
|
class Event implements EventInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* The event name. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $name; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The subject. |
25
|
|
|
* |
26
|
|
|
* @var object |
27
|
|
|
*/ |
28
|
|
|
protected $subject; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Array of arguments. |
32
|
|
|
* |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
protected $arguments = []; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Whether the propagation is stopped. |
39
|
|
|
* |
40
|
|
|
* @var boolean |
41
|
|
|
*/ |
42
|
|
|
protected $propagationStopped = false; |
43
|
|
|
|
44
|
|
|
public function __construct($name, $subject = null, array $arguments = []) |
45
|
|
|
{ |
46
|
|
|
$this->name = $name; |
47
|
|
|
$this->subject = $subject; |
48
|
|
|
$this->arguments = $arguments; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Gets the event name. |
53
|
|
|
* |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
public function getName() |
57
|
|
|
{ |
58
|
|
|
return $this->name; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Sets the event name. |
63
|
|
|
* |
64
|
|
|
* @param $name |
65
|
|
|
*/ |
66
|
|
|
public function setName($name) |
67
|
|
|
{ |
68
|
|
|
$this->name = $name; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Sets the subject. |
73
|
|
|
* |
74
|
|
|
* @param $subject |
75
|
|
|
*/ |
76
|
|
|
public function setSubject($subject) |
77
|
|
|
{ |
78
|
|
|
$this->subject = $subject; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Gets the subject. |
83
|
|
|
* |
84
|
|
|
* @return null|object |
85
|
|
|
*/ |
86
|
|
|
public function getSubject() |
87
|
|
|
{ |
88
|
|
|
return $this->subject; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Sets a argument to the event. |
93
|
|
|
* |
94
|
|
|
* @param string $name |
95
|
|
|
* @param mixed $value |
96
|
|
|
*/ |
97
|
|
|
public function setArgument($name, $value) |
98
|
|
|
{ |
99
|
|
|
$this->arguments[$name] = $value; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Gets the argument by its key. |
104
|
|
|
* |
105
|
|
|
* @param string $name |
106
|
|
|
* |
107
|
|
|
* @return mixed |
108
|
|
|
*/ |
109
|
|
|
public function getArgument($name) |
110
|
|
|
{ |
111
|
|
|
return isset($this->arguments[$name]) ? $this->arguments[$name] : null; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Sets array of arguments. |
116
|
|
|
* |
117
|
|
|
* @param array $arguments |
118
|
|
|
*/ |
119
|
|
|
public function setArguments(array $arguments) |
120
|
|
|
{ |
121
|
|
|
$this->arguments = $arguments; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Gets all arguments. |
126
|
|
|
* |
127
|
|
|
* @return array |
128
|
|
|
*/ |
129
|
|
|
public function getArguments() |
130
|
|
|
{ |
131
|
|
|
return $this->arguments; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Stop event propagation. |
136
|
|
|
* |
137
|
|
|
* @return $this |
138
|
|
|
*/ |
139
|
|
|
public function stopPropagation() |
140
|
|
|
{ |
141
|
|
|
$this->propagationStopped = true; |
142
|
|
|
|
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Checks whether propagation was stopped. |
148
|
|
|
* |
149
|
|
|
* @return bool |
150
|
|
|
*/ |
151
|
|
|
public function isPropagationStopped() |
152
|
|
|
{ |
153
|
|
|
return $this->propagationStopped; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|