diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 0fa2591..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,9 +0,0 @@ -# Changelog - -## 1.1.0 - -- Added global dispatcher support - -## 1.0.0 - -- Initial release diff --git a/src/EventDispatcherInterface.php b/src/EventDispatcherInterface.php index 861da9c..ee9869b 100644 --- a/src/EventDispatcherInterface.php +++ b/src/EventDispatcherInterface.php @@ -44,7 +44,8 @@ public function off($callback = null, $event = null): void; * @api * @param string|EventInterface $event Event name or object * @param callable|null $until Invoke handlers until callback return value evaluate to true + * @param EventEmitterInterface|null $target * @return EventInterface Event object */ - public function emit($event, callable $until = null): EventInterface; + public function emit($event, callable $until = null, EventEmitterInterface $target = null): EventInterface; } diff --git a/src/EventDispatcherTrait.php b/src/EventDispatcherTrait.php index 9ae7c0d..8558a56 100644 --- a/src/EventDispatcherTrait.php +++ b/src/EventDispatcherTrait.php @@ -51,10 +51,10 @@ trait EventDispatcherTrait * @api * @param string|EventInterface $event Event name or object * @param callable|null $until Invoke handlers until callback return value evaluate to true + * @param EventEmitterInterface|null $target * @return EventInterface Event object - * @throws InvalidEventException Invalid event */ - public function emit($event, callable $until = null): EventInterface + public function emit($event, callable $until = null, EventEmitterInterface $target = null): EventInterface { $event = $this->normalizeEvent($event); $name = $event->getName(); @@ -71,7 +71,9 @@ public function emit($event, callable $until = null): EventInterface $event->setResults([]); $event->stop(false); - if ($this instanceof EventEmitterInterface) { + if ($target) { + $event->setTarget($target); + } elseif ($this instanceof EventEmitterInterface) { $event->setTarget($this); } diff --git a/src/EventEmitterInterface.php b/src/EventEmitterInterface.php index 9b1a29b..0e46bfa 100644 --- a/src/EventEmitterInterface.php +++ b/src/EventEmitterInterface.php @@ -20,7 +20,6 @@ interface EventEmitterInterface extends EventDispatcherInterface * Inject event dispatcher. * * @api - * @since 1.1.0 * @param EventDispatcherInterface $dispatcher */ public function setEventDispatcher(EventDispatcherInterface $dispatcher): void; diff --git a/src/EventEmitterTrait.php b/src/EventEmitterTrait.php index f39836d..dc8fade 100644 --- a/src/EventEmitterTrait.php +++ b/src/EventEmitterTrait.php @@ -24,7 +24,6 @@ trait EventEmitterTrait /** * Returns event dispatcher. * - * @since 1.1.0 * @return EventDispatcherInterface */ public function getEventDispatcher(): EventDispatcherInterface @@ -39,7 +38,6 @@ public function getEventDispatcher(): EventDispatcherInterface * Inject event dispatcher. * * @api - * @since 1.1.0 * @param EventDispatcherInterface $dispatcher */ public function setEventDispatcher(EventDispatcherInterface $dispatcher): void @@ -53,12 +51,12 @@ public function setEventDispatcher(EventDispatcherInterface $dispatcher): void * @api * @param string|EventInterface $event Event name or object * @param callable|null $until Invoke handlers until callback return value evaluate to true + * @param EventEmitterInterface|null $target * @return EventInterface Event object - * @throws InvalidEventException Invalid event */ - public function emit($event, callable $until = null): EventInterface + public function emit($event, callable $until = null, EventEmitterInterface $target = null): EventInterface { - return $this->getEventDispatcher()->emit($event, $until); + return $this->getEventDispatcher()->emit($event, $until, $this); } /**