1 | <?php |
||
51 | class Event extends ObjectAbstract implements EventInterface |
||
52 | { |
||
53 | /** |
||
54 | * event name |
||
55 | * |
||
56 | * @var string |
||
57 | * @access protected |
||
58 | */ |
||
59 | protected $name; |
||
60 | |||
61 | /** |
||
62 | * event context |
||
63 | * |
||
64 | * an object OR static class name (string) |
||
65 | * |
||
66 | * @var object|string|null |
||
67 | * @access protected |
||
68 | */ |
||
69 | protected $context; |
||
70 | |||
71 | /** |
||
72 | * event properties |
||
73 | * |
||
74 | * @var array |
||
75 | * @access protected |
||
76 | */ |
||
77 | protected $properties; |
||
78 | |||
79 | /** |
||
80 | * Results from the handlers |
||
81 | * |
||
82 | * @var array |
||
83 | * @access protected |
||
84 | */ |
||
85 | protected $results = []; |
||
86 | |||
87 | /** |
||
88 | * stop propagation |
||
89 | * |
||
90 | * @var bool |
||
91 | * @access protected |
||
92 | */ |
||
93 | protected $stopped = false; |
||
94 | |||
95 | /** |
||
96 | * Constructor |
||
97 | * |
||
98 | * @param string $eventName event name |
||
99 | * @param string|object|null $context event context, object or classname |
||
100 | * @param array $properties (optional) event properties |
||
101 | * @throws InvalidArgumentException if arguments not right |
||
102 | * @access public |
||
103 | * @api |
||
104 | */ |
||
105 | public function __construct( |
||
112 | |||
113 | /** |
||
114 | * {@inheritDoc} |
||
115 | */ |
||
116 | public function __invoke( |
||
125 | |||
126 | /** |
||
127 | * {@inheritDoc} |
||
128 | */ |
||
129 | public function setName(/*# string */ $eventName) |
||
141 | |||
142 | /** |
||
143 | * {@inheritDoc} |
||
144 | */ |
||
145 | public function getName()/*# : string */ |
||
149 | |||
150 | /** |
||
151 | * {@inheritDoc} |
||
152 | */ |
||
153 | public function setContext($context) |
||
154 | { |
||
155 | if (is_null($context) || |
||
156 | $this->isValidContext($context) |
||
157 | ) { |
||
158 | $this->context = $context; |
||
159 | return $this; |
||
160 | } |
||
161 | throw new InvalidArgumentException( |
||
162 | Message::get(Message::EVT_CONTEXT_INVALID, $context), |
||
163 | Message::EVT_CONTEXT_INVALID |
||
164 | ); |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * {@inheritDoc} |
||
169 | */ |
||
170 | public function getContext() |
||
174 | |||
175 | /** |
||
176 | * {@inheritDoc} |
||
177 | */ |
||
178 | public function hasProperty(/*# string */ $name)/*#: bool */ |
||
182 | |||
183 | /** |
||
184 | * {@inheritDoc} |
||
185 | */ |
||
186 | public function getProperty(/*# string */ $name) |
||
193 | |||
194 | /** |
||
195 | * {@inheritDoc} |
||
196 | */ |
||
197 | public function setProperty(/*# string */ $name, $value) |
||
206 | |||
207 | /** |
||
208 | * {@inheritDoc} |
||
209 | */ |
||
210 | public function getProperties()/*# : array */ |
||
214 | |||
215 | /** |
||
216 | * {@inheritDoc} |
||
217 | */ |
||
218 | public function setProperties(array $properties) |
||
223 | |||
224 | /** |
||
225 | * {@inheritDoc} |
||
226 | */ |
||
227 | public function addResult($result) |
||
232 | |||
233 | /** |
||
234 | * {@inheritDoc} |
||
235 | */ |
||
236 | public function getResults()/*# : array */ |
||
240 | |||
241 | /** |
||
242 | * {@inheritDoc} |
||
243 | */ |
||
244 | public function stopPropagation(/*# bool */ $stop = true) |
||
249 | |||
250 | /** |
||
251 | * {@inheritDoc} |
||
252 | */ |
||
253 | public function isPropagationStopped()/*# : bool */ |
||
257 | |||
258 | /** |
||
259 | * {@inheritDoc} |
||
260 | */ |
||
261 | public function offsetExists($offset)/*# : bool */ |
||
265 | |||
266 | /** |
||
267 | * {@inheritDoc} |
||
268 | */ |
||
269 | public function offsetGet($offset) |
||
273 | |||
274 | /** |
||
275 | * {@inheritDoc} |
||
276 | */ |
||
277 | public function offsetSet($offset, $value) |
||
281 | |||
282 | /** |
||
283 | * {@inheritDoc} |
||
284 | */ |
||
285 | public function offsetUnset($offset) |
||
289 | |||
290 | /** |
||
291 | * Is valid context |
||
292 | * |
||
293 | * @param mixed $context |
||
294 | * @return bool |
||
295 | * @access protected |
||
296 | */ |
||
297 | protected function isValidContext($context)/*# : bool */ |
||
307 | } |
||
308 |