From 38f6830190fbb9f03765f36491cc8dfa75c18a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Thu, 16 Jun 2022 18:13:27 +0800 Subject: [PATCH] modify plugin name --- EventProvider.php | 10 +++++++--- Struct.php | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/EventProvider.php b/EventProvider.php index de2168f..af42703 100644 --- a/EventProvider.php +++ b/EventProvider.php @@ -32,11 +32,15 @@ class EventProvider implements ListenerProviderInterface /** * @param string $event - * @param callable $handler + * @param array|\Closure|string $handler * @param int $zOrder + * @throws \Exception */ - public function on(string $event, callable $handler, int $zOrder = 1) + public function on(string $event, array|\Closure|string $handler, int $zOrder = 1) { + if (is_string($handler) && !is_callable($handler, true)) { + throw new \Exception('Event handler must is execute function.'); + } $this->_listeners[$event][] = new Struct($event, $handler, $zOrder); } @@ -46,7 +50,7 @@ class EventProvider implements ListenerProviderInterface * @param callable $handler * @return void */ - public function off(string $event, callable $handler) + public function off(string $event, callable $handler): void { $events = $this->_listeners[$event] ?? []; diff --git a/Struct.php b/Struct.php index 4ed935a..6cbe236 100644 --- a/Struct.php +++ b/Struct.php @@ -12,11 +12,11 @@ class Struct public string $event; - public array|\Closure $listener; + public array|\Closure|string $listener; public int $priority; - public function __construct(string $event, callable $listener, int $priority) + public function __construct(string $event, array|\Closure|string $listener, int $priority) { $this->event = $event; $this->listener = $listener;