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 fa08827 commit 7c0bb5b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ php artisan larke-admin:import-route

- laravel/framework

- [lake/larke-jwt](https://github.com/deatil/larke-jwt) (代码修改自 lcobucci/jwt)

- casbin/casbin

- composer/semver
Expand Down
4 changes: 2 additions & 2 deletions src/larke/admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class Admin
/**
* 版本号
*/
const VERSION = "2.0.8";
const VERSION = "2.0.9";

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

/**
* 扩展
Expand Down
2 changes: 1 addition & 1 deletion src/larke/admin/Events/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/larke/admin/Events/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Larke\Admin\Events;

use Iterator;
use ReflectionClass;
use ReflectionMethod;

Expand Down Expand Up @@ -253,6 +254,19 @@ protected function dispatch($event, array $params = [])
return $this->pool->call($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/larke/admin/Events/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function trigger($event, $params = null, ...$var)

$tmp = $var;
$result = $params;
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 7c0bb5b

Please sign in to comment.