diff --git a/src/ProvidesEvents.php b/src/ProvidesEvents.php index 07d0f71..ab54179 100644 --- a/src/ProvidesEvents.php +++ b/src/ProvidesEvents.php @@ -45,6 +45,19 @@ trait ProvidesEvents */ public function setEventManager(EventCollection $events) { + $identifiers = array(__CLASS__, get_class($this)); + if (isset($this->eventIdentifier)) { + if ((is_string($this->eventIdentifier)) + || (is_array($this->eventIdentifier)) + || ($this->eventIdentifier instanceof Traversable) + ) { + $identifiers = array_unique(array_merge($identifiers, (array) $this->eventIdentifier)); + } elseif (is_object($this->eventIdentifier)) { + $identifiers[] = $this->eventIdentifier; + } + // silently ignore invalid eventIdentifier types + } + $events->setIdentifiers($identifiers); $this->events = $events; return $this; } @@ -59,19 +72,7 @@ public function setEventManager(EventCollection $events) public function events() { if (!$this->events instanceof EventCollection) { - $identifiers = array(__CLASS__, get_class($this)); - if (isset($this->eventIdentifier)) { - if ((is_string($this->eventIdentifier)) - || (is_array($this->eventIdentifier)) - || ($this->eventIdentifier instanceof Traversable) - ) { - $identifiers = array_unique(array_merge($identifiers, (array) $this->eventIdentifier)); - } elseif (is_object($this->eventIdentifier)) { - $identifiers[] = $this->eventIdentifier; - } - // silently ignore invalid eventIdentifier types - } - $this->setEventManager(new EventManager($identifiers)); + $this->setEventManager(new EventManager()); } return $this->events; }