改名
This commit is contained in:
@@ -9,6 +9,7 @@ use Exception;
|
|||||||
use HttpServer\Abstracts\Callback;
|
use HttpServer\Abstracts\Callback;
|
||||||
use HttpServer\Http\Context;
|
use HttpServer\Http\Context;
|
||||||
use Snowflake\Abstracts\Config;
|
use Snowflake\Abstracts\Config;
|
||||||
|
use Snowflake\Core\Json;
|
||||||
use Snowflake\Event;
|
use Snowflake\Event;
|
||||||
use Snowflake\Exception\ComponentException;
|
use Snowflake\Exception\ComponentException;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
@@ -31,19 +32,21 @@ class OnMessage extends Callback
|
|||||||
public function onHandler(Server $server, Frame $frame)
|
public function onHandler(Server $server, Frame $frame)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if ($frame->opcode != 0x08) {
|
Coroutine::defer(function () {
|
||||||
$event = Snowflake::app()->getEvent();
|
fire(Event::SYSTEM_RESOURCE_RELEASES);
|
||||||
$content = $this->resolve($event, $frame, $server);
|
Snowflake::app()->getLogger()->insert();
|
||||||
if (!empty($content)) {
|
});
|
||||||
$server->send($frame->fd, $content);
|
if ($frame->opcode == 0x08) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
$event = Snowflake::app()->getEvent();
|
||||||
|
$content = $this->resolve($event, $frame, $server);
|
||||||
|
if (!empty($content)) {
|
||||||
|
$server->send($frame->fd, $content);
|
||||||
}
|
}
|
||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
$this->addError($exception, 'websocket');
|
$this->addError($exception, 'websocket');
|
||||||
$server->send($frame->fd, $exception->getMessage());
|
$server->send($frame->fd, $exception->getMessage());
|
||||||
} finally {
|
|
||||||
fire(Event::SYSTEM_RESOURCE_RELEASES);
|
|
||||||
logger()->insert();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use Snowflake\Event;
|
|||||||
use Snowflake\Exception\ComponentException;
|
use Snowflake\Exception\ComponentException;
|
||||||
use Snowflake\Exception\NotFindClassException;
|
use Snowflake\Exception\NotFindClassException;
|
||||||
use Snowflake\Snowflake;
|
use Snowflake\Snowflake;
|
||||||
|
use Swoole\Coroutine;
|
||||||
use Swoole\Error;
|
use Swoole\Error;
|
||||||
use Swoole\Http\Request;
|
use Swoole\Http\Request;
|
||||||
use Swoole\Http\Response;
|
use Swoole\Http\Response;
|
||||||
@@ -36,20 +37,21 @@ class OnRequest extends Callback
|
|||||||
public function onHandler(Request $request, Response $response): mixed
|
public function onHandler(Request $request, Response $response): mixed
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
Coroutine::defer(function () use ($request) {
|
||||||
|
write(Json::encode(get_object_vars($request)), 'request');
|
||||||
|
fire(Event::SYSTEM_RESOURCE_RELEASES);
|
||||||
|
});
|
||||||
[$req, $rep] = static::create($request, $response);
|
[$req, $rep] = static::create($request, $response);
|
||||||
if ($req->is('favicon.ico')) {
|
if ($req->is('favicon.ico')) {
|
||||||
return \send(null, 404);
|
return \send(null, 404);
|
||||||
}
|
}
|
||||||
return \router()->dispatch();
|
return \router()->dispatch();
|
||||||
} catch (ExitException | Error | \Throwable $exception) {
|
} catch (ExitException | Error | \Throwable $exception) {
|
||||||
$this->addError($exception);
|
$this->addError($exception);
|
||||||
if ($exception instanceof ExitException) {
|
if ($exception instanceof ExitException) {
|
||||||
return \send($exception->getMessage(), $exception->getCode());
|
return \send($exception->getMessage(), $exception->getCode());
|
||||||
}
|
}
|
||||||
return $this->sendErrorMessage($exception);
|
return $this->sendErrorMessage($exception);
|
||||||
} finally {
|
|
||||||
write(Json::encode(get_object_vars($request)), 'request');
|
|
||||||
fire(Event::SYSTEM_RESOURCE_RELEASES);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user