From d528f82b1468283a6972a0d096eee0cdec595f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Proch=C3=A1zka?= Date: Mon, 19 Aug 2024 16:13:26 +0200 Subject: [PATCH] Added event pre-sorting --- src/Traits/Events.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Traits/Events.php b/src/Traits/Events.php index 1edb018..879e5c5 100644 --- a/src/Traits/Events.php +++ b/src/Traits/Events.php @@ -37,6 +37,10 @@ public function &__get(string $name): array $event = substr($event, 3); $this->isWatched($event, true); + + // Pre-sort current events before returning array reference + ksort($this->events[$event], SORT_NUMERIC); + return $this->events[$event]; } @@ -62,8 +66,8 @@ public function __isset(string $name): bool */ public function isWatched(string $event, bool $throw = false): bool { - $isWatched = isset($this->events[$event]); $event = Format::kebabCase($event); + $isWatched = isset($this->events[$event]); if (!$isWatched && $this instanceof EventAutoWatch) { $this->watch($event, true); @@ -131,7 +135,6 @@ protected function unwatch(string $event): static protected function trigger(string $event, mixed ...$args): void { $event = Format::kebabCase($event); - $this->isWatched($event, true); ksort($this->events[$event], SORT_NUMERIC);