1 | <?php |
||
18 | class Event |
||
19 | { |
||
20 | /** |
||
21 | * @var string event name |
||
22 | */ |
||
23 | protected $name; |
||
24 | |||
25 | /** |
||
26 | * @var string|object the event target |
||
27 | */ |
||
28 | protected $target; |
||
29 | |||
30 | /** |
||
31 | * @var array|object the event parameters |
||
32 | */ |
||
33 | protected $params = []; |
||
34 | |||
35 | /** |
||
36 | * Constructor |
||
37 | * |
||
38 | * Accept a target and its parameters. |
||
39 | * |
||
40 | * @param string $name Event name |
||
41 | * @param string|object $target |
||
42 | * @param array|object $params |
||
43 | * |
||
44 | * @throws EventException |
||
45 | */ |
||
46 | 11 | public function __construct($name, $target = null, $params = null) |
|
58 | |||
59 | /** |
||
60 | * Get event name |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | 8 | public function getName() : string |
|
68 | |||
69 | /** |
||
70 | * Get the event target |
||
71 | * |
||
72 | * This may be either an object, or the name of a static method. |
||
73 | * |
||
74 | * @return string|object |
||
75 | */ |
||
76 | 8 | public function getTarget() |
|
80 | |||
81 | /** |
||
82 | * Overwrites parameters |
||
83 | * |
||
84 | * @param array|object $params |
||
85 | * |
||
86 | * @return void |
||
87 | * @throws EventException |
||
88 | */ |
||
89 | 5 | public function setParams($params) : void |
|
99 | |||
100 | /** |
||
101 | * Get all parameters |
||
102 | * |
||
103 | * @return array|object |
||
104 | */ |
||
105 | 2 | public function getParams() |
|
109 | |||
110 | /** |
||
111 | * Get an individual parameter |
||
112 | * |
||
113 | * If the parameter does not exist, the $default value will be returned. |
||
114 | * |
||
115 | * @param string|int $name |
||
116 | * @param mixed $default |
||
117 | * |
||
118 | * @return mixed |
||
119 | */ |
||
120 | 3 | public function getParam($name, $default = null) |
|
133 | |||
134 | /** |
||
135 | * Set the event name |
||
136 | * |
||
137 | * @param string $name |
||
138 | * |
||
139 | * @return void |
||
140 | */ |
||
141 | 11 | public function setName($name) : void |
|
145 | |||
146 | /** |
||
147 | * Set the event target/context |
||
148 | * |
||
149 | * @param null|string|object $target |
||
150 | * |
||
151 | * @return void |
||
152 | */ |
||
153 | 4 | public function setTarget($target) : void |
|
157 | |||
158 | /** |
||
159 | * Set an individual parameter to a value |
||
160 | * |
||
161 | * @param string|int $name |
||
162 | * @param mixed $value |
||
163 | * |
||
164 | * @return void |
||
165 | */ |
||
166 | 2 | public function setParam($name, $value) : void |
|
176 | } |
||
177 |