Revert "改名"
This reverts commit fdf58326
This commit is contained in:
@@ -13,9 +13,9 @@ namespace Kiri\Abstracts;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use JetBrains\PhpStorm\Pure;
|
use JetBrains\PhpStorm\Pure;
|
||||||
use Kiri\Di\Container;
|
use Kiri\Di\Container;
|
||||||
|
use Kiri\Events\EventDispatch;
|
||||||
use Kiri\Events\EventProvider;
|
use Kiri\Events\EventProvider;
|
||||||
use Kiri\Kiri;
|
use Kiri\Kiri;
|
||||||
use Note\Inject;
|
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
@@ -25,12 +25,12 @@ use Psr\Container\NotFoundExceptionInterface;
|
|||||||
* @package Kiri\Kiri\Base
|
* @package Kiri\Kiri\Base
|
||||||
* @property ContainerInterface|Container $container
|
* @property ContainerInterface|Container $container
|
||||||
* @property EventProvider $eventProvider
|
* @property EventProvider $eventProvider
|
||||||
|
* @property EventDispatch $eventDispatch
|
||||||
*/
|
*/
|
||||||
class Component implements Configure
|
class Component implements Configure
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BaseAbstract constructor.
|
* BaseAbstract constructor.
|
||||||
*
|
*
|
||||||
@@ -65,6 +65,14 @@ class Component implements Configure
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return EventDispatch
|
||||||
|
*/
|
||||||
|
protected function getEventDispatch(): EventDispatch
|
||||||
|
{
|
||||||
|
return Kiri::getDi()->get(EventDispatch::class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@@ -73,7 +81,6 @@ class Component implements Configure
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -124,13 +131,14 @@ class Component implements Configure
|
|||||||
public function addError($message, string $model = 'app'): bool
|
public function addError($message, string $model = 'app'): bool
|
||||||
{
|
{
|
||||||
if ($message instanceof \Throwable) {
|
if ($message instanceof \Throwable) {
|
||||||
$this->error(jTraceEx($message));
|
$this->error($message = jTraceEx($message));
|
||||||
} else {
|
} else {
|
||||||
if (!is_string($message)) {
|
if (!is_string($message)) {
|
||||||
$message = json_encode($message, JSON_UNESCAPED_UNICODE);
|
$message = json_encode($message, JSON_UNESCAPED_UNICODE);
|
||||||
}
|
}
|
||||||
$this->error($message);
|
$this->error($message);
|
||||||
}
|
}
|
||||||
|
Kiri::app()->getLogger()->fail($message, $model);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,8 +164,6 @@ class Component implements Configure
|
|||||||
if (!is_string($message)) {
|
if (!is_string($message)) {
|
||||||
$message = print_r($message, true);
|
$message = print_r($message, true);
|
||||||
}
|
}
|
||||||
// $message = "\033[35m" . $message . "\033[0m";
|
|
||||||
|
|
||||||
$context = [];
|
$context = [];
|
||||||
if (!empty($method)) $context['method'] = $method;
|
if (!empty($method)) $context['method'] = $method;
|
||||||
if (!empty($file)) $context['file'] = $file;
|
if (!empty($file)) $context['file'] = $file;
|
||||||
@@ -177,8 +183,6 @@ class Component implements Configure
|
|||||||
if (!is_string($message)) {
|
if (!is_string($message)) {
|
||||||
$message = print_r($message, true);
|
$message = print_r($message, true);
|
||||||
}
|
}
|
||||||
// $message = "\033[34m" . $message . "\033[0m";
|
|
||||||
|
|
||||||
$context = [];
|
$context = [];
|
||||||
if (!empty($method)) $context['method'] = $method;
|
if (!empty($method)) $context['method'] = $method;
|
||||||
if (!empty($file)) $context['file'] = $file;
|
if (!empty($file)) $context['file'] = $file;
|
||||||
@@ -198,9 +202,6 @@ class Component implements Configure
|
|||||||
if (!is_string($message)) {
|
if (!is_string($message)) {
|
||||||
$message = print_r($message, true);
|
$message = print_r($message, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// $message = "\033[36m" . $message . "\033[0m";
|
|
||||||
|
|
||||||
$context = [];
|
$context = [];
|
||||||
if (!empty($method)) $context['method'] = $method;
|
if (!empty($method)) $context['method'] = $method;
|
||||||
if (!empty($file)) $context['file'] = $file;
|
if (!empty($file)) $context['file'] = $file;
|
||||||
@@ -221,8 +222,6 @@ class Component implements Configure
|
|||||||
$message = print_r($message, true);
|
$message = print_r($message, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// $message = "\033[33m" . $message . "\033[0m";
|
|
||||||
|
|
||||||
$context = [];
|
$context = [];
|
||||||
if (!empty($method)) $context['method'] = $method;
|
if (!empty($method)) $context['method'] = $method;
|
||||||
if (!empty($file)) $context['file'] = $file;
|
if (!empty($file)) $context['file'] = $file;
|
||||||
@@ -252,8 +251,6 @@ class Component implements Configure
|
|||||||
}
|
}
|
||||||
$context = $method;
|
$context = $method;
|
||||||
}
|
}
|
||||||
// $message = "\033[41;37m" . $message . "\033[0m";
|
|
||||||
|
|
||||||
if (!empty($method)) $context['method'] = $method;
|
if (!empty($method)) $context['method'] = $method;
|
||||||
if (!empty($file)) $context['file'] = $file;
|
if (!empty($file)) $context['file'] = $file;
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Kiri\Error;
|
namespace Kiri\Error;
|
||||||
|
|
||||||
use Note\Inject;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri\Abstracts\Component;
|
use Kiri\Abstracts\Component;
|
||||||
use Kiri\Core\Json;
|
use Kiri\Core\Json;
|
||||||
use Kiri\Kiri;
|
use Kiri\Kiri;
|
||||||
|
use Note\Inject;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
@@ -46,9 +46,21 @@ class Logger extends Component
|
|||||||
*/
|
*/
|
||||||
public function getLastError(string $application = 'app'): string
|
public function getLastError(string $application = 'app'): string
|
||||||
{
|
{
|
||||||
return 'Unknown error.';
|
return $this->logs[$application] ?? 'Unknown error.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $message
|
||||||
|
* @param $method
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function fail($message, $method)
|
||||||
|
{
|
||||||
|
$this->logs[$method] = $message;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $messages
|
* @param string $messages
|
||||||
* @param string $method
|
* @param string $method
|
||||||
|
|||||||
@@ -56,10 +56,6 @@ class Server extends AbstractServer implements OnHandshakeInterface, OnMessageIn
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->callback = $handler->callback[0];
|
$this->callback = $handler->callback[0];
|
||||||
|
|
||||||
$this->server->on(Constant::HANDSHAKE, [$this, 'onHandshake']);
|
|
||||||
$this->server->on(Constant::MESSAGE, [$this, 'onMessage']);
|
|
||||||
$this->server->on(Constant::CLOSE, [$this, 'onClose']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -114,7 +110,7 @@ class Server extends AbstractServer implements OnHandshakeInterface, OnMessageIn
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if ($this->callback instanceof OnHandshakeInterface) {
|
if ($this->callback instanceof OnHandshakeInterface) {
|
||||||
$this->__handshake($request, $response);
|
$this->callback->onHandshake($request, $response);
|
||||||
} else {
|
} else {
|
||||||
$this->protocol($request, $response);
|
$this->protocol($request, $response);
|
||||||
}
|
}
|
||||||
@@ -129,64 +125,6 @@ class Server extends AbstractServer implements OnHandshakeInterface, OnMessageIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Request $request
|
|
||||||
* @param Response $response
|
|
||||||
* @return void
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private function __handshake(Request $request, Response $response)
|
|
||||||
{
|
|
||||||
$this->callback->onHandshake($request, $response);
|
|
||||||
$key = base64_encode(sha1($request->header['sec-websocket-key'] . self::SHA1_KEY, true));
|
|
||||||
if ($key != $response->header['Sec-Websocket-Accept']) {
|
|
||||||
throw new Exception('Protocol fail.');
|
|
||||||
}
|
|
||||||
$response->setStatusCode(101, 'connection success.');
|
|
||||||
$response->end();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Request $request
|
|
||||||
* @param Response $response
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private function _coroutine_server(Request $request, Response $response)
|
|
||||||
{
|
|
||||||
if ($this->server instanceof \Swoole\Coroutine\Http\Server) {
|
|
||||||
$response->upgrade();
|
|
||||||
$this->afterHandshake($request);
|
|
||||||
while (true) {
|
|
||||||
$data = $response->recv();
|
|
||||||
if ($data === '' || $data === false || $data instanceof CloseFrame) {
|
|
||||||
if (!($this->callback instanceof OnCloseInterface)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$this->callback->onClose($this->server, $response->fd);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!($this->callback instanceof OnMessageInterface)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$this->callback->onMessage($this->server, $data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $request
|
|
||||||
*/
|
|
||||||
public function afterHandshake($request)
|
|
||||||
{
|
|
||||||
if (!($this->callback instanceof OnOpenInterface)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->callback->onOpen($this->server, $request);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Swoole\Server $server
|
* @param \Swoole\Server $server
|
||||||
* @param Frame $frame
|
* @param Frame $frame
|
||||||
|
|||||||
Reference in New Issue
Block a user