Skip to content

Commit

Permalink
优化事件
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Aug 6, 2024
1 parent 02c2afc commit 5033165
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class Admin
/**
* 版本号
*/
const VERSION = "1.5.10";
const VERSION = "1.5.11";

/**
* 发布号
*/
const RELEASE = "20240731";
const RELEASE = "20240806";

/**
* 插件
Expand Down
2 changes: 1 addition & 1 deletion src/Event/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function trigger($event, ...$var): void

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

foreach ($listeners as $key => $listener) {
foreach ($this->range($listeners) as $listener) {
$this->dispatch($listener['listener'], $var);
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/Event/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Laket\Admin\Event;

use Iterator;
use ReflectionClass;
use ReflectionMethod;

Expand Down Expand Up @@ -256,6 +257,19 @@ protected function dispatch($event, array $params = [])
return $this->app->invoke($call, $params);
}

/**
* 迭代数据
*
* @param array $data 数据
* @return Iterator
*/
protected function range(array $data = []): Iterator
{
foreach ($data as $k => $v) {
yield $k => $v;
}
}

/**
* 排序
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Event/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function trigger($event, $value = null, ...$var)

$tmp = $var;
$result = $value;
foreach ($listeners as $key => $listener) {
foreach ($this->range($listeners) as $listener) {
array_unshift($tmp, $result);

$result = $this->dispatch($listener['listener'], $tmp);
Expand Down

0 comments on commit 5033165

Please sign in to comment.