This commit is contained in:
2021-04-27 15:57:50 +08:00
parent 4fbb525059
commit 0b2523ba9f
22 changed files with 73 additions and 287 deletions
+5 -6
View File
@@ -7,6 +7,7 @@ namespace Annotation;
use Exception; use Exception;
use Snowflake\Exception\ComponentException; use Snowflake\Exception\ComponentException;
use Snowflake\Snowflake; use Snowflake\Snowflake;
use Snowflake\Event as SEvent;
/** /**
@@ -29,16 +30,14 @@ use Snowflake\Snowflake;
/** /**
* @param array $handler * @param array $handler
* @return \Snowflake\Event * @return bool
* @throws ComponentException
* @throws Exception * @throws Exception
*/ */
public function execute(array $handler): \Snowflake\Event public function execute(array $handler): bool
{ {
// TODO: Implement execute() method. // TODO: Implement execute() method.
$event = Snowflake::app()->getEvent(); SEvent::on($this->name, $handler, $this->params);
$event->on($this->name, $handler, $this->params); return true;
return $event;
} }
} }
+1 -2
View File
@@ -28,8 +28,7 @@ use Snowflake\Snowflake;
if ($this->async_reload !== true) { if ($this->async_reload !== true) {
return; return;
} }
$event = Snowflake::app()->getEvent(); Event::on(Event::SERVER_WORKER_EXIT, function () {
$event->on(Event::SERVER_WORKER_EXIT, function () {
Snowflake::app()->remove($this->service); Snowflake::app()->remove($this->service);
}); });
} }
+4 -6
View File
@@ -67,9 +67,8 @@ class Connection extends Component
*/ */
public function init() public function init()
{ {
$event = Snowflake::app()->getEvent(); Event::on(Event::SYSTEM_RESOURCE_CLEAN, [$this, 'disconnect']);
$event->on(Event::SYSTEM_RESOURCE_CLEAN, [$this, 'disconnect']); Event::on(Event::SYSTEM_RESOURCE_RELEASES, [$this, 'clear_connection']);
$event->on(Event::SYSTEM_RESOURCE_RELEASES, [$this, 'clear_connection']);
} }
@@ -83,9 +82,8 @@ class Connection extends Component
} }
$this->beginTransaction(); $this->beginTransaction();
$event = Snowflake::app()->getEvent(); Event::on(Connection::TRANSACTION_COMMIT, [$this, 'commit'], false, true);
$event->on(Connection::TRANSACTION_COMMIT, [$this, 'commit'], false, true); Event::on(Connection::TRANSACTION_ROLLBACK, [$this, 'rollback'], false, true);
$event->on(Connection::TRANSACTION_ROLLBACK, [$this, 'rollback'], false, true);
} }
/** /**
+1 -2
View File
@@ -33,8 +33,7 @@ class DatabasesProviders extends Providers
{ {
$application->set('db', $this); $application->set('db', $this);
$event = Snowflake::app()->getEvent(); Event::on(Event::SERVER_WORKER_START, [$this, 'createPool']);
$event->on(Event::SERVER_WORKER_START, [$this, 'createPool']);
} }
+5 -6
View File
@@ -12,6 +12,7 @@ namespace Database;
use Database\Traits\QueryTrait; use Database\Traits\QueryTrait;
use Exception; use Exception;
use HttpServer\Http\Context; use HttpServer\Http\Context;
use Snowflake\Event;
use Snowflake\Snowflake; use Snowflake\Snowflake;
/** /**
@@ -49,9 +50,8 @@ class Db
if (!static::transactionsActive()) { if (!static::transactionsActive()) {
return; return;
} }
$event = Snowflake::app()->getEvent(); Event::trigger(Connection::TRANSACTION_COMMIT);
$event->trigger(Connection::TRANSACTION_COMMIT); Event::offName(Connection::TRANSACTION_COMMIT);
$event->offName(Connection::TRANSACTION_COMMIT);
static::$_inTransaction = false; static::$_inTransaction = false;
} }
@@ -63,9 +63,8 @@ class Db
if (!static::transactionsActive()) { if (!static::transactionsActive()) {
return; return;
} }
$event = Snowflake::app()->getEvent(); Event::trigger(Connection::TRANSACTION_ROLLBACK);
$event->trigger(Connection::TRANSACTION_ROLLBACK); Event::offName(Connection::TRANSACTION_ROLLBACK);
$event->offName(Connection::TRANSACTION_ROLLBACK);
static::$_inTransaction = false; static::$_inTransaction = false;
} }
-66
View File
@@ -1,66 +0,0 @@
<?php
defined('CONNECT_HOST') or define('CONNECT_HOST', '');
defined('CONNECT_USER') or define('CONNECT_USER', '');
defined('CONNECT_PASS') or define('CONNECT_PASS', '');
return [
'cache' => [
'file' => [
'path' => strpos(null, 'data')
],
'redis' => [
'host' => '127.0.0.1',
'port' => '6379',
'prefix' => 'cache_',
'auth' => '',
'databases' => '0',
'timeout' => -1,
'read_timeout' => -1,
],
],
'databases' => [
'db' => [
'id' => 'db',
'cds' => 'mysql:dbname=aircraftwar;host=' . CONNECT_HOST,
'username' => CONNECT_USER,
'password' => CONNECT_PASS,
'tablePrefix' => 'aircraftwar_',
'maxNumber' => 100,
'slaveConfig' => [
'cds' => 'mysql:dbname=aircraftwar;host=' . CONNECT_HOST,
'username' => CONNECT_USER,
'password' => CONNECT_PASS
],
],
'server' => [
'id' => 'server',
'cds' => 'mysql:dbname=server;host=' . CONNECT_HOST,
'username' => CONNECT_USER,
'password' => CONNECT_PASS,
'tablePrefix' => 'master_',
'maxNumber' => 100,
'slaveConfig' => [
'cds' => 'mysql:dbname=server;host=' . CONNECT_HOST,
'username' => CONNECT_USER,
'password' => CONNECT_PASS
],
],
'game' => [
'id' => 'game',
'cds' => 'mysql:dbname=game;host=' . CONNECT_HOST,
'username' => CONNECT_USER,
'password' => CONNECT_PASS,
'maxNumber' => 100,
'tablePrefix' => 'game_',
'slaveConfig' => [
'cds' => 'mysql:dbname=game;host=' . CONNECT_HOST,
'username' => CONNECT_USER,
'password' => CONNECT_PASS
],
],
]
];
+1 -3
View File
@@ -21,13 +21,11 @@ class OnAfterReload extends Callback
/** /**
* @param Server $server * @param Server $server
* @throws ComponentException
* @throws Exception * @throws Exception
*/ */
public function onHandler(Server $server) public function onHandler(Server $server)
{ {
$event = Snowflake::app()->getEvent(); Event::trigger(Event::SERVER_AFTER_RELOAD, [$server]);
$event->trigger(Event::SERVER_AFTER_RELOAD, [$server]);
} }
} }
+1 -2
View File
@@ -24,8 +24,7 @@ class OnBeforeReload extends Callback
*/ */
public function onHandler(Server $server) public function onHandler(Server $server)
{ {
$event = Snowflake::app()->getEvent(); Event::trigger(Event::SERVER_BEFORE_RELOAD, [$server]);
$event->trigger(Event::SERVER_BEFORE_RELOAD, [$server]);
Snowflake::clearWorkerPid(); Snowflake::clearWorkerPid();
Snowflake::clearTaskPid(); Snowflake::clearTaskPid();
+2 -4
View File
@@ -31,12 +31,10 @@ class OnClose extends Callback
fire(Event::SYSTEM_RESOURCE_RELEASES); fire(Event::SYSTEM_RESOURCE_RELEASES);
}); });
$clientInfo = $server->getClientInfo($fd); $clientInfo = $server->getClientInfo($fd);
$event = Snowflake::app()->getEvent(); if (!Event::exists(($name = $this->getName($clientInfo)))) {
if (!$event->exists(($name = $this->getName($clientInfo)))) {
return; return;
} }
$event->trigger($name, [$server, $fd]); Event::trigger($name, [$server, $fd]);
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
$this->addError($exception, 'throwable'); $this->addError($exception, 'throwable');
} }
+2 -4
View File
@@ -45,12 +45,10 @@ class OnMessage extends Callback
return; return;
} }
$clientInfo = $server->getClientInfo($frame->fd); $clientInfo = $server->getClientInfo($frame->fd);
$event = Snowflake::app()->getEvent(); if (!Event::exists(($name = $this->getName($clientInfo)))) {
if (!$event->exists(($name = $this->getName($clientInfo)))) {
return; return;
} }
$event->trigger($name, [$frame, $server]); Event::trigger($name, [$frame, $server]);
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
$this->addError($exception, 'websocket'); $this->addError($exception, 'websocket');
if (!swoole()->exist($frame->fd)) { if (!swoole()->exist($frame->fd)) {
-3
View File
@@ -38,7 +38,6 @@ class OnRequest extends Callback
*/ */
public function init() public function init()
{ {
$this->event = Snowflake::app()->getEvent();
$this->router = Snowflake::app()->getRouter(); $this->router = Snowflake::app()->getRouter();
} }
@@ -93,8 +92,6 @@ class OnRequest extends Callback
[$sRequest, $sResponse] = [HRequest::create($sRequest), HResponse::create($sResponse)]; [$sRequest, $sResponse] = [HRequest::create($sRequest), HResponse::create($sResponse)];
} }
$this->event->dispatch(Event::EVENT_AFTER_REQUEST, [$sRequest, $exception]);
$headers = $sRequest->headers->get('access-control-request-headers'); $headers = $sRequest->headers->get('access-control-request-headers');
$methods = $sRequest->headers->get('access-control-request-method'); $methods = $sRequest->headers->get('access-control-request-method');
+1 -2
View File
@@ -28,8 +28,7 @@ class OnWorkerError extends Callback
*/ */
public function onHandler(Server $server, int $worker_id, int $worker_pid, int $exit_code, int $signal) public function onHandler(Server $server, int $worker_id, int $worker_pid, int $exit_code, int $signal)
{ {
$event = Snowflake::app()->getEvent(); Event::trigger(Event::SERVER_WORKER_ERROR);
$event->trigger(Event::SERVER_WORKER_ERROR);
$message = sprintf('Worker#%d::%d error stop. signal %d, exit_code %d', $message = sprintf('Worker#%d::%d error stop. signal %d, exit_code %d',
$worker_id, $signal, $worker_pid, $exit_code $worker_id, $signal, $worker_pid, $exit_code
+1 -2
View File
@@ -25,11 +25,10 @@ class OnWorkerExit extends Callback
public function onHandler($server, $worker_id) public function onHandler($server, $worker_id)
{ {
putenv('state=exit'); putenv('state=exit');
$event = Snowflake::app()->getEvent();
$channel = Snowflake::app()->getChannel(); $channel = Snowflake::app()->getChannel();
$channel->cleanAll(); $channel->cleanAll();
$event->trigger(Event::SERVER_WORKER_EXIT); Event::trigger(Event::SERVER_WORKER_EXIT);
logger()->insert(); logger()->insert();
} }
+1 -2
View File
@@ -26,8 +26,7 @@ class OnWorkerStop extends Callback
*/ */
public function onHandler($server, $worker_id) public function onHandler($server, $worker_id)
{ {
$event = Snowflake::app()->getEvent(); Event::trigger(Event::SERVER_WORKER_STOP);
$event->trigger(Event::SERVER_WORKER_STOP);
$this->clearMysqlClient(); $this->clearMysqlClient();
$this->clearRedisClient(); $this->clearRedisClient();
+2 -2
View File
@@ -17,6 +17,7 @@ use Exception;
use ReflectionException; use ReflectionException;
use Snowflake\Abstracts\Config; use Snowflake\Abstracts\Config;
use Snowflake\Error\LoggerProcess; use Snowflake\Error\LoggerProcess;
use Snowflake\Event;
use Snowflake\Exception\ConfigException; use Snowflake\Exception\ConfigException;
use Snowflake\Exception\NotFindClassException; use Snowflake\Exception\NotFindClassException;
use Snowflake\Process\Biomonitoring; use Snowflake\Process\Biomonitoring;
@@ -300,9 +301,8 @@ class Server extends HttpService
if (!is_array($config['events'])) { if (!is_array($config['events'])) {
return; return;
} }
$event = Snowflake::app()->getEvent();
foreach ($config['events'] as $name => $_event) { foreach ($config['events'] as $name => $_event) {
$event->on('listen ' . $config['port'] . ' ' . $name, $_event); Event::on('listen ' . $config['port'] . ' ' . $name, $_event);
} }
} }
-111
View File
@@ -1,111 +0,0 @@
<?php
use HttpServer\Server;
use Snowflake\Snowflake;
use Snowflake\Event;
use Swoole\Http\Request;
use Swoole\Http\Response;
use Swoole\WebSocket\Frame;
return [
'servers' => [
[
'id' => '',
'type' => Server::HTTP,
'host' => '127.0.0.1',
'port' => 9527,
'settings' => [
'worker_num' => 10,
'enable_coroutine' => 1
],
'events' => [
Event::SERVER_WORKER_START => function () {
$router = Snowflake::app()->getRouter();
$router->loadRouterSetting();
},
]
],
[
'id' => '',
'type' => Server::PACKAGE,
'host' => '127.0.0.1',
'port' => 9628,
'settings' => [
'worker_num' => 10,
'enable_coroutine' => 1
],
'message' => [
'pack' => function ($data) {
return \Snowflake\Core\Json::encode($data);
},
'unpack' => function ($data) {
return \Snowflake\Core\Json::decode($data);
},
],
'events' => [
]
],
[
'id' => '',
'type' => Server::TCP,
'host' => '127.0.0.1',
'port' => 9629,
'settings' => [
'worker_num' => 10,
'enable_coroutine' => 1
],
'message' => [
'pack' => function ($data) {
return \Snowflake\Core\Json::encode($data);
},
'unpack' => function ($data) {
return \Snowflake\Core\Json::decode($data);
},
],
'events' => [
Event::RECEIVE_CONNECTION => function ($data) {
return 'hello word~';
}
]
],
[
'id' => '',
'type' => Server::WEBSOCKET,
'host' => '127.0.0.1',
'port' => 9530,
'settings' => [
'worker_num' => 10,
'enable_coroutine' => 1
],
'events' => [
Event::SERVER_WORKER_START => function () {
$path = APP_PATH . 'app/Websocket';
$websocket = Snowflake::app()->annotation->websocket;
$websocket->registration_notes($path, 'App\\Sockets\\');
},
Event::SERVER_HANDSHAKE => function (Request $request, Response $response) {
$this->error($request->fd . ' connect.');
$response->status(101);
$response->end();
},
Event::SERVER_MESSAGE => function (\Swoole\WebSocket\Server $server, Frame $frame) {
$this->error('websocket SERVER_MESSAGE.');
if (is_null($json = json_decode($frame->data, true))) {
return $server->push($frame->fd, 'format error~');
}
$websocket = Snowflake::app()->annotation->websocket;
if ($websocket->has($json['path'])) {
return $websocket->runWith($json['path'], [$frame->fd, $json]);
} else {
return $server->push($frame->fd, 'hello word~');
}
},
Event::SERVER_CLOSE => function (int $fd) {
$this->error($fd . ' disconnect.');
return 'hello word~';
}
]
],
]
];
+8 -20
View File
@@ -180,43 +180,42 @@ abstract class BaseApplication extends Service
if (!isset($config['events']) || !is_array($config['events'])) { if (!isset($config['events']) || !is_array($config['events'])) {
return; return;
} }
$event = Snowflake::app()->getEvent();
foreach ($config['events'] as $key => $value) { foreach ($config['events'] as $key => $value) {
if (is_string($value)) { if (is_string($value)) {
$value = Snowflake::createObject($value); $value = Snowflake::createObject($value);
} }
$this->addEvent($event, $key, $value); $this->addEvent($key, $value);
} }
} }
/** /**
* @param $event
* @param $key * @param $key
* @param $value * @param $value
* @throws InitException * @throws InitException
* @throws NotFindClassException * @throws NotFindClassException
* @throws ReflectionException * @throws ReflectionException
* @throws Exception
*/ */
private function addEvent($event, $key, $value): void private function addEvent($key, $value): void
{ {
if ($value instanceof \Closure) { if ($value instanceof \Closure) {
$event->on($key, $value, [], true); Event::on($key, $value, [], true);
return; return;
} }
if (is_object($value)) { if (is_object($value)) {
$event->on($key, $value, [], true); Event::on($key, $value, [], true);
return; return;
} }
if (is_array($value)) { if (is_array($value)) {
if (is_object($value[0]) && !($value[0] instanceof \Closure)) { if (is_object($value[0]) && !($value[0] instanceof \Closure)) {
$event->on($key, $value, [], true); Event::on($key, $value, [], true);
return; return;
} }
if (is_string($value[0])) { if (is_string($value[0])) {
$value[0] = Snowflake::createObject($value[0]); $value[0] = Snowflake::createObject($value[0]);
$event->on($key, $value, [], true); Event::on($key, $value, [], true);
return; return;
} }
@@ -224,7 +223,7 @@ abstract class BaseApplication extends Service
if (!is_callable($item, true)) { if (!is_callable($item, true)) {
throw new InitException("Class does not hav callback."); throw new InitException("Class does not hav callback.");
} }
$event->on($key, $item, [], true); Event::on($key, $item, [], true);
} }
} }
@@ -367,16 +366,6 @@ abstract class BaseApplication extends Service
} }
/**
* @return Event
* @throws Exception
*/
public function getEvent(): Event
{
return $this->get('event');
}
/** /**
* @return Jwt * @return Jwt
* @throws Exception * @throws Exception
@@ -454,7 +443,6 @@ abstract class BaseApplication extends Service
{ {
$this->setComponents([ $this->setComponents([
'error' => ['class' => ErrorHandler::class], 'error' => ['class' => ErrorHandler::class],
'event' => ['class' => Event::class],
'connections' => ['class' => Connection::class], 'connections' => ['class' => Connection::class],
'redis_connections' => ['class' => SRedis::class], 'redis_connections' => ['class' => SRedis::class],
'pool' => ['class' => SPool::class], 'pool' => ['class' => SPool::class],
+3 -4
View File
@@ -35,10 +35,9 @@ class Redis extends Component
*/ */
public function init() public function init()
{ {
$event = Snowflake::app()->getEvent(); Event::on(Event::SYSTEM_RESOURCE_CLEAN, [$this, 'destroy']);
$event->on(Event::SYSTEM_RESOURCE_CLEAN, [$this, 'destroy']); Event::on(Event::SYSTEM_RESOURCE_RELEASES, [$this, 'release']);
$event->on(Event::SYSTEM_RESOURCE_RELEASES, [$this, 'release']); Event::on(Event::SERVER_WORKER_START, [$this, 'createPool']);
$event->on(Event::SERVER_WORKER_START, [$this, 'createPool']);
} }
+2 -4
View File
@@ -74,8 +74,7 @@ class ErrorHandler extends Component implements ErrorInterface
{ {
$this->category = 'exception'; $this->category = 'exception';
$event = Snowflake::app()->getEvent(); Event::trigger(Event::SYSTEM_RESOURCE_CLEAN);
$event->trigger(Event::SYSTEM_RESOURCE_CLEAN);
$this->sendError($exception->getMessage(), $exception->getFile(), $exception->getLine()); $this->sendError($exception->getMessage(), $exception->getFile(), $exception->getLine());
} }
@@ -103,8 +102,7 @@ class ErrorHandler extends Component implements ErrorInterface
Snowflake::app()->error($data, 'error'); Snowflake::app()->error($data, 'error');
$event = Snowflake::app()->getEvent(); Event::trigger(Event::SYSTEM_RESOURCE_CLEAN);
$event->trigger(Event::SYSTEM_RESOURCE_CLEAN);
throw new \ErrorException($error[1], $error[0], 1, $error[2], $error[3]); throw new \ErrorException($error[1], $error[0], 1, $error[2], $error[3]);
} }
+2 -3
View File
@@ -33,9 +33,8 @@ class Logger extends Component
public function init() public function init()
{ {
$event = Snowflake::app()->getEvent(); Event::on(Event::SYSTEM_RESOURCE_CLEAN, [$this, 'insert']);
$event->on(Event::SYSTEM_RESOURCE_CLEAN, [$this, 'insert']); Event::on(Event::SYSTEM_RESOURCE_RELEASES, [$this, 'insert']);
$event->on(Event::SYSTEM_RESOURCE_RELEASES, [$this, 'insert']);
} }
+20 -20
View File
@@ -71,7 +71,7 @@ class Event extends BaseObject
* @param bool $isAppend * @param bool $isAppend
* @throws Exception * @throws Exception
*/ */
public function on($name, $callback, $parameter = [], $isAppend = false) public static function on($name, $callback, $parameter = [], $isAppend = false)
{ {
if (!isset(static::$_events[$name])) { if (!isset(static::$_events[$name])) {
static::$_events[$name] = []; static::$_events[$name] = [];
@@ -84,7 +84,7 @@ class Event extends BaseObject
} }
$callback[0] = Snowflake::createObject($callback[0]); $callback[0] = Snowflake::createObject($callback[0]);
} }
if ($this->exists($name, $callback)) { if (static::exists($name, $callback)) {
return; return;
} }
if (!empty(static::$_events[$name]) && $isAppend === true) { if (!empty(static::$_events[$name]) && $isAppend === true) {
@@ -99,7 +99,7 @@ class Event extends BaseObject
* @param $name * @param $name
* @param $callback * @param $callback
*/ */
public function of($name, $callback): void public static function of($name, $callback): void
{ {
if (!isset(static::$_events[$name])) { if (!isset(static::$_events[$name])) {
return; return;
@@ -118,13 +118,13 @@ class Event extends BaseObject
* @param $name * @param $name
* @return bool * @return bool
*/ */
public function offName($name): bool public static function offName($name): bool
{ {
if (!$this->exists($name)) { if (!static::exists($name)) {
return true; return true;
} }
unset(static::$_events[$name]); unset(static::$_events[$name]);
return $this->exists($name); return static::exists($name);
} }
@@ -133,7 +133,7 @@ class Event extends BaseObject
* @param null $callback * @param null $callback
* @return bool * @return bool
*/ */
public function exists($name, $callback = null): bool public static function exists($name, $callback = null): bool
{ {
if (!isset(static::$_events[$name])) { if (!isset(static::$_events[$name])) {
return false; return false;
@@ -156,9 +156,9 @@ class Event extends BaseObject
* @param $handler * @param $handler
* @return mixed * @return mixed
*/ */
public function get($name, $handler): mixed public static function get($name, $handler): mixed
{ {
if (!$this->exists($name, $handler)) { if (!static::exists($name, $handler)) {
return null; return null;
} }
@@ -175,7 +175,7 @@ class Event extends BaseObject
} }
public function clean() public static function clean()
{ {
static::$_events = []; static::$_events = [];
} }
@@ -188,9 +188,9 @@ class Event extends BaseObject
* @return bool * @return bool
* @throws Exception * @throws Exception
*/ */
public function dispatch($name, $params = [], $scope = null): bool public static function dispatch($name, $params = [], $scope = null): bool
{ {
return $this->trigger($name, $params, $scope); return static::trigger($name, $params, $scope);
} }
@@ -202,17 +202,17 @@ class Event extends BaseObject
* @return bool * @return bool
* @throws Exception * @throws Exception
*/ */
public function trigger($name, $parameter = null, $handler = null, $is_remove = false): bool public static function trigger($name, $parameter = null, $handler = null, $is_remove = false): bool
{ {
$events = $this->get($name, $handler); $events = static::get($name, $handler);
if (empty($events)) { if (empty($events)) {
return true; return true;
} }
foreach ($events as $event) { foreach ($events as $event) {
$this->execute($event, $parameter); static::execute($event, $parameter);
} }
if ($is_remove) { if ($is_remove) {
$this->offName($name); static::offName($name);
} }
return true; return true;
} }
@@ -224,16 +224,16 @@ class Event extends BaseObject
* @return bool * @return bool
* @throws Exception * @throws Exception
*/ */
private function execute($event, $parameter): bool private static function execute($event, $parameter): bool
{ {
try { try {
$meta = $this->mergeParams($event[1], $parameter); $meta = static::mergeParams($event[1], $parameter);
if (call_user_func($event[0], ...$meta) === false) { if (call_user_func($event[0], ...$meta) === false) {
return false; return false;
} }
return true; return true;
} catch (\Throwable $throwable) { } catch (\Throwable $throwable) {
return $this->addError($throwable,'throwable'); return static::addError($throwable,'throwable');
} }
} }
@@ -243,7 +243,7 @@ class Event extends BaseObject
* @param $parameter * @param $parameter
* @return array * @return array
*/ */
private function mergeParams($defaultParameter, $parameter = []): array private static function mergeParams($defaultParameter, $parameter = []): array
{ {
if (empty($defaultParameter)) { if (empty($defaultParameter)) {
$defaultParameter = $parameter; $defaultParameter = $parameter;
+4 -6
View File
@@ -19,6 +19,7 @@ use Snowflake\Abstracts\Config;
use Snowflake\Application; use Snowflake\Application;
use Snowflake\Core\ArrayAccess; use Snowflake\Core\ArrayAccess;
use Snowflake\Error\Logger; use Snowflake\Error\Logger;
use Snowflake\Event;
use Snowflake\Exception\ConfigException; use Snowflake\Exception\ConfigException;
use Snowflake\Snowflake; use Snowflake\Snowflake;
use Swoole\WebSocket\Server; use Swoole\WebSocket\Server;
@@ -350,8 +351,7 @@ if (!function_exists('fire')) {
*/ */
function fire(string $event, array $params = []) function fire(string $event, array $params = [])
{ {
$logger = Snowflake::app()->getEvent(); Event::trigger($event, $params);
$logger->trigger($event, $params);
} }
} }
@@ -586,8 +586,7 @@ if (!function_exists('listen')) {
*/ */
function listen($name, $callback, $params = [], $isAppend = true) function listen($name, $callback, $params = [], $isAppend = true)
{ {
$event = Snowflake::app()->getEvent(); Event::on($name, $callback, $params, $isAppend);
$event->on($name, $callback, $params, $isAppend);
} }
} }
@@ -606,8 +605,7 @@ if (!function_exists('event')) {
*/ */
function event($name, $callback, $params = [], $isAppend = true) function event($name, $callback, $params = [], $isAppend = true)
{ {
$event = Snowflake::app()->getEvent(); Event::on($name, $callback, $params, $isAppend);
$event->on($name, $callback, $params, $isAppend);
} }
} }