From ffda04002012d5679c83261c0414df1ae7c3b8c9 Mon Sep 17 00:00:00 2001 From: chipslays Date: Wed, 3 Jul 2024 10:44:15 +0400 Subject: [PATCH] wip --- src/Alisa.php | 10 +++++----- src/Events/Dispatcher.php | 4 +++- src/Support/Concerns/HasAnyHandler.php | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Alisa.php b/src/Alisa.php index dff6908..564ad1c 100644 --- a/src/Alisa.php +++ b/src/Alisa.php @@ -201,21 +201,21 @@ public function onDangerous(Closure|array|string $handler, int $priority = 0): E return $this->dispatcher->onDangerous($handler, $priority); } - public function onAny(Closure $handler): static + public function onAny(Closure|array|string $handler, int $priority = 0): static { - $this->dispatcher->onAny($handler); + $this->dispatcher->onAny($handler, $priority); return $this; } - public function onFallback(Closure $handler): static + public function onFallback(Closure|array|string $handler): static { $this->dispatcher->onFallback($handler); return $this; } - public function onError(Closure $callback): static + public function onError(Closure|array|string $callback): static { $this->onErrorHandler = $callback; @@ -250,7 +250,7 @@ public function run(): void } } catch (Throwable $th) { if ($this->onErrorHandler) { - call_user_func($this->onErrorHandler, $this->context, $th); + call_handler($this->onErrorHandler, $this->context, $th); } else { throw $th; } diff --git a/src/Events/Dispatcher.php b/src/Events/Dispatcher.php index 4fd9f84..a372c78 100644 --- a/src/Events/Dispatcher.php +++ b/src/Events/Dispatcher.php @@ -8,6 +8,8 @@ use Alisa\Support\Concerns\HasFallbackHandler; use Closure; +use function Alisa\Support\Helpers\call_handler; + class Dispatcher extends Group { use HasFallbackHandler, HasAnyHandler; @@ -74,7 +76,7 @@ public function dispatch(Context $context): void $fallback = function (Context $context) use ($fallback) { if (!$this->matched && $fallback) { - $fallback($context); + call_handler($fallback, $context); } }; diff --git a/src/Support/Concerns/HasAnyHandler.php b/src/Support/Concerns/HasAnyHandler.php index 96d0511..5b54b23 100644 --- a/src/Support/Concerns/HasAnyHandler.php +++ b/src/Support/Concerns/HasAnyHandler.php @@ -6,7 +6,7 @@ trait HasAnyHandler { - public function onAny(Closure $handler, int $priority = 0): static + public function onAny(Closure|array|string $handler, int $priority = 0): static { $this->on('request.type', $handler, $priority);