4 Commits

Author SHA1 Message Date
as2252258 100ce506ea modify plugin name 2022-03-03 18:30:59 +08:00
as2252258 a4c50f975e modify plugin name 2022-02-23 16:32:08 +08:00
as2252258 f7630a4c2a Revert "改名"
This reverts commit fdf58326
2022-01-20 19:04:16 +08:00
as2252258 bf3182660b Revert "改名"
This reverts commit fdf58326
2022-01-14 11:29:16 +08:00
2 changed files with 31 additions and 2 deletions
+16 -2
View File
@@ -2,8 +2,10 @@
namespace Kiri\Events;
use Kiri\Abstracts\Component;
use Kiri;
use Kiri\Abstracts\Component;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\EventDispatcher\StoppableEventInterface;
@@ -15,10 +17,22 @@ class EventDispatch extends Component implements EventDispatcherInterface
{
/**
* @param EventProvider $eventProvider
* @param array $config
* @throws \Exception
*/
public function __construct(public EventProvider $eventProvider, array $config = [])
{
parent::__construct($config);
}
/**
* @param object $event
* @return object
* @throws \ReflectionException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function dispatch(object $event): object
{
+15
View File
@@ -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;
});
}
}