Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chipslays committed Jul 3, 2024
1 parent f3a2f61 commit ffda040
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/Alisa.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Events/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/Support/Concerns/HasAnyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit ffda040

Please sign in to comment.