Skip to content

Commit

Permalink
Added event pre-sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk authored Aug 19, 2024
1 parent 6303e70 commit d528f82
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Traits/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit d528f82

Please sign in to comment.