改名
This commit is contained in:
@@ -21,13 +21,11 @@ class OnAfterReload extends Callback
|
||||
|
||||
/**
|
||||
* @param Server $server
|
||||
* @throws ComponentException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function onHandler(Server $server)
|
||||
{
|
||||
$event = Snowflake::app()->getEvent();
|
||||
$event->trigger(Event::SERVER_AFTER_RELOAD, [$server]);
|
||||
Event::trigger(Event::SERVER_AFTER_RELOAD, [$server]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,8 +24,7 @@ class OnBeforeReload extends Callback
|
||||
*/
|
||||
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::clearTaskPid();
|
||||
|
||||
@@ -31,12 +31,10 @@ class OnClose extends Callback
|
||||
fire(Event::SYSTEM_RESOURCE_RELEASES);
|
||||
});
|
||||
$clientInfo = $server->getClientInfo($fd);
|
||||
$event = Snowflake::app()->getEvent();
|
||||
|
||||
if (!$event->exists(($name = $this->getName($clientInfo)))) {
|
||||
if (!Event::exists(($name = $this->getName($clientInfo)))) {
|
||||
return;
|
||||
}
|
||||
$event->trigger($name, [$server, $fd]);
|
||||
Event::trigger($name, [$server, $fd]);
|
||||
} catch (\Throwable $exception) {
|
||||
$this->addError($exception, 'throwable');
|
||||
}
|
||||
|
||||
@@ -45,12 +45,10 @@ class OnMessage extends Callback
|
||||
return;
|
||||
}
|
||||
$clientInfo = $server->getClientInfo($frame->fd);
|
||||
$event = Snowflake::app()->getEvent();
|
||||
|
||||
if (!$event->exists(($name = $this->getName($clientInfo)))) {
|
||||
if (!Event::exists(($name = $this->getName($clientInfo)))) {
|
||||
return;
|
||||
}
|
||||
$event->trigger($name, [$frame, $server]);
|
||||
Event::trigger($name, [$frame, $server]);
|
||||
} catch (\Throwable $exception) {
|
||||
$this->addError($exception, 'websocket');
|
||||
if (!swoole()->exist($frame->fd)) {
|
||||
|
||||
@@ -38,7 +38,6 @@ class OnRequest extends Callback
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->event = Snowflake::app()->getEvent();
|
||||
$this->router = Snowflake::app()->getRouter();
|
||||
}
|
||||
|
||||
@@ -93,8 +92,6 @@ class OnRequest extends Callback
|
||||
[$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');
|
||||
$methods = $sRequest->headers->get('access-control-request-method');
|
||||
|
||||
|
||||
@@ -28,8 +28,7 @@ class OnWorkerError extends Callback
|
||||
*/
|
||||
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',
|
||||
$worker_id, $signal, $worker_pid, $exit_code
|
||||
|
||||
@@ -25,11 +25,10 @@ class OnWorkerExit extends Callback
|
||||
public function onHandler($server, $worker_id)
|
||||
{
|
||||
putenv('state=exit');
|
||||
$event = Snowflake::app()->getEvent();
|
||||
$channel = Snowflake::app()->getChannel();
|
||||
$channel->cleanAll();
|
||||
|
||||
$event->trigger(Event::SERVER_WORKER_EXIT);
|
||||
Event::trigger(Event::SERVER_WORKER_EXIT);
|
||||
|
||||
logger()->insert();
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@ class OnWorkerStop extends Callback
|
||||
*/
|
||||
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->clearRedisClient();
|
||||
|
||||
@@ -17,6 +17,7 @@ use Exception;
|
||||
use ReflectionException;
|
||||
use Snowflake\Abstracts\Config;
|
||||
use Snowflake\Error\LoggerProcess;
|
||||
use Snowflake\Event;
|
||||
use Snowflake\Exception\ConfigException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Process\Biomonitoring;
|
||||
@@ -300,9 +301,8 @@ class Server extends HttpService
|
||||
if (!is_array($config['events'])) {
|
||||
return;
|
||||
}
|
||||
$event = Snowflake::app()->getEvent();
|
||||
foreach ($config['events'] as $name => $_event) {
|
||||
$event->on('listen ' . $config['port'] . ' ' . $name, $_event);
|
||||
Event::on('listen ' . $config['port'] . ' ' . $name, $_event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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~';
|
||||
}
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
Reference in New Issue
Block a user