This commit is contained in:
2021-07-21 18:56:05 +08:00
parent 68c8850922
commit 52fdb0e89c
2 changed files with 208 additions and 216 deletions
+1 -1
View File
@@ -93,7 +93,7 @@ class HTTPServerListener extends Abstracts\Server
public function onRequest(Request $request, Response $response)
{
try {
// defer(fn() => fire(Event::SYSTEM_RESOURCE_RELEASES));
defer(fn() => fire(Event::SYSTEM_RESOURCE_RELEASES));
[$request, $_] = [HRequest::create($request), HResponse::create($response)];
if ($request->is('favicon.ico')) {
+5 -13
View File
@@ -6,9 +6,7 @@ namespace Snowflake;
use Exception;
use JetBrains\PhpStorm\Pure;
use Snowflake\Abstracts\BaseObject;
use Snowflake\Core\ArrayAccess;
/**
* Class Event
@@ -200,31 +198,25 @@ class Event extends BaseObject
/**
* @param $name
* @param array $params
* @param null $scope
* @return bool
* @throws Exception
*/
public function dispatch($name, array $params = [], $scope = null): bool
public function dispatch($name, array $params = []): bool
{
return static::trigger($name, $params, $scope);
return static::trigger($name, $params);
}
/**
* @param $name
* @param null $parameter
* @param null $handler
* @param false $is_remove
* @return bool
* @throws Exception
*/
public static function trigger($name, $parameter = null, $handler = null, bool $is_remove = false): bool
public static function trigger($name, $parameter = null, bool $is_remove = false): bool
{
$events = static::get($name, $handler);
if (empty($events)) {
return true;
}
foreach ($events as $event) {
foreach ((static::$_events[$name] ?? []) as $event) {
static::execute($event, $parameter);
}
if ($is_remove) {
@@ -249,7 +241,7 @@ class Event extends BaseObject
}
return true;
} catch (\Throwable $throwable) {
return logger()->addError($throwable,'throwable');
return logger()->addError($throwable, 'throwable');
}
}