summaryrefslogtreecommitdiff
path: root/app/Core
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-05-26 12:27:33 -0400
committerFrédéric Guillot <fred@kanboard.net>2014-05-26 12:27:33 -0400
commit2cb6b77ac87c52e9655a1333d39d0263b4880ed5 (patch)
tree0539622e8cf589a1f71ffe8ddcbfcc0a4122579f /app/Core
parentdbc4443bb18ab2f588b5f8e2f6dbec4332a46660 (diff)
Improve events handling
Diffstat (limited to 'app/Core')
-rw-r--r--app/Core/Event.php27
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