diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-05-26 12:27:33 -0400 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-05-26 12:27:33 -0400 |
commit | 2cb6b77ac87c52e9655a1333d39d0263b4880ed5 (patch) | |
tree | 0539622e8cf589a1f71ffe8ddcbfcc0a4122579f /app/Core/Event.php | |
parent | dbc4443bb18ab2f588b5f8e2f6dbec4332a46660 (diff) |
Improve events handling
Diffstat (limited to 'app/Core/Event.php')
-rw-r--r-- | app/Core/Event.php | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/app/Core/Event.php b/app/Core/Event.php index 2c029b49..ac81bf87 100644 --- a/app/Core/Event.php +++ b/app/Core/Event.php @@ -67,13 +67,16 @@ class Event */ public function trigger($eventName, array $data) { - $this->lastEvent = $eventName; - $this->events[] = $eventName; + if (! $this->isEventTriggered($eventName)) { - if (isset($this->listeners[$eventName])) { - foreach ($this->listeners[$eventName] as $listener) { - if ($listener->execute($data)) { - $this->lastListener = get_class($listener); + $this->lastEvent = $eventName; + $this->events[] = $eventName; + + if (isset($this->listeners[$eventName])) { + foreach ($this->listeners[$eventName] as $listener) { + if ($listener->execute($data)) { + $this->lastListener = get_class($listener); + } } } } @@ -113,6 +116,18 @@ class Event } /** + * Check if an event have been triggered + * + * @access public + * @param string $eventName Event name + * @return bool + */ + public function isEventTriggered($eventName) + { + return in_array($eventName, $this->events); + } + + /** * Check if a listener bind to an event * * @access public |