fix:修复BUG/升级1.1.6版本

This commit is contained in:
Ying
2023-04-25 20:11:49 +08:00
parent 445e5f9662
commit 6a6866bbaf
2357 changed files with 456920 additions and 140567 deletions

View File

@@ -63,9 +63,8 @@ class Event
* @param bool $halt
* @return array|null|mixed
*/
public static function emit($event_name, $data, $halt = false)
public static function emit($event_name, $data, bool $halt = false)
{
$success_count = 0;
$listeners = static::getListeners($event_name);
$responses = [];
foreach ($listeners as $listener) {
@@ -91,6 +90,29 @@ class Event
}
return $halt ? null : $responses;
}
/**
* @param mixed $event_name
* @param mixed $data
* @param bool $halt
* @return array|null|mixed
*/
public static function dispatch($event_name, $data, bool $halt = false)
{
$listeners = static::getListeners($event_name);
$responses = [];
foreach ($listeners as $listener) {
$response = $listener($data, $event_name);
$responses[] = $response;
if ($halt && !is_null($response)) {
return $response;
}
if ($response === false) {
break;
}
}
return $halt ? null : $responses;
}
/**
* @return array
@@ -136,4 +158,4 @@ class Event
{
return !empty(static::getListeners($event_name));
}
}
}