From 2cb6b77ac87c52e9655a1333d39d0263b4880ed5 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Mon, 26 May 2014 12:27:33 -0400 Subject: Improve events handling --- app/Core/Event.php | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'app/Core/Event.php') 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); + } } } } @@ -112,6 +115,18 @@ class Event return $this->events; } + /** + * 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 * -- cgit v1.2.3