fix:修复BUG/升级1.1.6版本
This commit is contained in:
28
vendor/webman/event/src/Event.php
vendored
28
vendor/webman/event/src/Event.php
vendored
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user