Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a4c50f975e | |||
| f7630a4c2a | |||
| bf3182660b |
+5
-2
@@ -4,6 +4,8 @@ namespace Kiri\Events;
|
||||
|
||||
use Kiri\Abstracts\Component;
|
||||
use Kiri;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||
use Psr\EventDispatcher\StoppableEventInterface;
|
||||
|
||||
@@ -18,11 +20,12 @@ class EventDispatch extends Component implements EventDispatcherInterface
|
||||
/**
|
||||
* @param object $event
|
||||
* @return object
|
||||
* @throws \ReflectionException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function dispatch(object $event): object
|
||||
{
|
||||
$lists = $this->eventProvider->getListenersForEvent($event);
|
||||
$lists = $this->getEventProvider()->getListenersForEvent($event);
|
||||
foreach ($lists as $listener) {
|
||||
/** @var Struct $list */
|
||||
$listener($event);
|
||||
|
||||
@@ -41,4 +41,19 @@ class EventProvider implements ListenerProviderInterface
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $event
|
||||
* @param callable $handler
|
||||
* @return void
|
||||
*/
|
||||
public function off(string $event, callable $handler)
|
||||
{
|
||||
$events = $this->_listeners[$event] ?? [];
|
||||
|
||||
$this->_listeners[$event] = array_filter($events, function ($value) use ($handler) {
|
||||
return $value->listener !== $handler;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user