Skip to content

Commit

Permalink
优化事件
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Jul 28, 2024
1 parent 2d100f1 commit c310981
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
10 changes: 3 additions & 7 deletions src/Event/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,17 @@ public function trigger($event, ...$var): void
$listeners = $this->listener[$event] ?? [];

if (str_contains($event, '.*')) {
$needSort = false;
[$prefix, $event] = explode('.', $event, 2);

foreach ($this->listener as $e => $listener) {
if ($event == '*' && str_starts_with($e, $prefix . '.')) {
$listeners = array_merge($listeners, $listener);
$needSort = true;
}
}

if ($needSort) {
$listeners = $this->arraySort($listeners, 'sort');
}
}

$listeners = $this->arraySort($listeners, 'sort');

foreach ($listeners as $key => $listener) {
$this->dispatch($listener['listener'], $var);
}
Expand Down
2 changes: 0 additions & 2 deletions src/Event/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public function listen(string $event, $listener, int $sort = 1)
'key' => $this->filterBuildUniqueId($listener),
];

$this->listener[$event] = $this->arraySort($this->listener[$event], 'sort');

return $this;
}

Expand Down
10 changes: 3 additions & 7 deletions src/Event/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,17 @@ public function trigger($event, $value = null, ...$var)
$listeners = $this->listener[$event] ?? [];

if (str_contains($event, '.*')) {
$needSort = false;
[$prefix, $event] = explode('.', $event, 2);

foreach ($this->listener as $e => $listener) {
if ($event == '*' && str_starts_with($e, $prefix . '.')) {
$listeners = array_merge($listeners, $listener);
$needSort = true;
}
}

if ($needSort) {
$listeners = $this->arraySort($listeners, 'sort');
}
}

$listeners = $this->arraySort($listeners, 'sort');

$tmp = $var;
$result = $value;
foreach ($listeners as $key => $listener) {
Expand Down
4 changes: 2 additions & 2 deletions src/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use Laket\Admin\Model\Attachment as AttachmentModel;

// 版本号
define("LAKET_VERSION", "1.5.7");
define("LAKET_RELEASE", "1.5.7.20240728");
define("LAKET_VERSION", "1.5.8");
define("LAKET_RELEASE", "1.5.8.20240729");

if (! function_exists('make')) {
/**
Expand Down

0 comments on commit c310981

Please sign in to comment.