Compare commits

...

8 Commits

Author SHA1 Message Date
as2252258 73cb94f657 改名 2021-07-09 14:38:49 +08:00
as2252258 b3ea8978b1 改名 2021-07-09 14:24:23 +08:00
as2252258 008a0914eb 改名 2021-07-09 13:55:52 +08:00
as2252258 01f8e16b38 改名 2021-07-09 13:41:06 +08:00
as2252258 c095b69f67 改名 2021-07-09 10:41:31 +08:00
as2252258 4c8c5ac239 改名 2021-07-09 10:36:45 +08:00
as2252258 cfc847133e 改名 2021-07-09 10:34:27 +08:00
as2252258 30b430f1cf 改名 2021-07-08 19:16:27 +08:00
4 changed files with 1041 additions and 1015 deletions
+1 -3
View File
@@ -8,9 +8,7 @@ use Exception;
use HttpServer\Abstracts\HttpService;
use HttpServer\Controller;
use HttpServer\Exception\RequestException;
use HttpServer\Http\Context;
use HttpServer\Http\Request;
use HttpServer\Http\Response;
use HttpServer\IInterface\Middleware;
use HttpServer\IInterface\RouterInterface;
use JetBrains\PhpStorm\Pure;
@@ -506,7 +504,7 @@ class Router extends HttpService implements RouterInterface
{
$node = $this->find_path(\request());
if (!($node instanceof Node)) {
throw new RequestException(self::NOT_FOUND, 404);
throw new RequestException(\request()->getUri() . ' -> ' . self::NOT_FOUND, 404);
}
send(($response = $node->dispatch()), 200);
if (!$node->hasAfter()) {
+14 -14
View File
@@ -39,7 +39,7 @@ class Logger extends Component
/**
* @param $message
* @param mixed $message
* @param string $method
* @param null $file
* @throws Exception
@@ -51,18 +51,18 @@ class Logger extends Component
/**
* @param $message
* @param mixed $message
* @param string $method
* @throws Exception
*/
public function trance($message, $method = 'app')
public function trance(mixed $message, string $method = 'app')
{
$this->writer($message, $method);
}
/**
* @param $message
* @param mixed $message
* @param string $method
* @param null $file
* @throws Exception
@@ -73,12 +73,12 @@ class Logger extends Component
}
/**
* @param $message
* @param mixed $message
* @param string $method
* @param null $file
* @throws Exception
*/
public function success(mixed $message, $method = 'app', $file = null)
public function success(mixed $message, string $method = 'app', $file = null)
{
$this->writer($message, $method);
}
@@ -89,7 +89,7 @@ class Logger extends Component
* @return string
* @throws Exception
*/
private function writer($message, $method = 'app'): string
private function writer($message, string $method = 'app'): string
{
$this->print_r($message, $method);
if ($message instanceof Throwable) {
@@ -114,10 +114,10 @@ class Logger extends Component
/**
* @param $message
* @param $method
* @param string $method
* @throws Exception
*/
public function print_r($message, $method = '')
public function print_r($message, string $method = '')
{
$debug = Config::get('debug', ['enable' => false]);
if ((bool)$debug['enable'] === true) {
@@ -145,7 +145,7 @@ class Logger extends Component
* @param string $application
* @return mixed
*/
public function getLastError($application = 'app'): mixed
public function getLastError(string $application = 'app'): mixed
{
$filetype = [];
foreach ($this->logs as $key => $val) {
@@ -161,14 +161,14 @@ class Logger extends Component
}
/**
* @param $messages
* @param string $messages
* @param string $method
* @throws
* @throws Exception
*/
public function write(string $messages, $method = 'app')
public function write(string $messages, string $method = 'app')
{
if (empty($messages)) {
return;
if (empty($messages)) {
}
$fileName = 'server-' . date('Y-m-d') . '.log';
+22 -2
View File
@@ -5,11 +5,12 @@ namespace Snowflake\Jwt;
use Exception;
use HttpServer\Http\HttpHeaders;
use Snowflake\Cache\Redis;
use Snowflake\Abstracts\Component;
use Snowflake\Abstracts\Config;
use Snowflake\Cache\Redis;
use Snowflake\Core\Json;
use Snowflake\Core\Str;
use Snowflake\Exception\AuthException;
use Snowflake\Abstracts\Component;
use Snowflake\Exception\ConfigException;
use Snowflake\Snowflake;
@@ -222,6 +223,25 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
return $this->create($this->user, $headers);
}
/**
* @param array $headers
* @return mixed
* @throws AuthException
*/
public function getTokenUser(array $headers = []): int
{
$this->data = $headers;
if (!openssl_public_decrypt(base64_decode($headers['refresh']), $data, $this->public)) {
throw new AuthException('信息解码失败.');
}
$data = Json::decode($data, true);
return (int)$data['user'];
}
/**
* @param array $param
*
+9 -1
View File
@@ -81,6 +81,11 @@ class ClientsPool extends Component
{
if (env('state') == 'exit') {
Timer::clear($this->creates);
foreach (static::$_connections as $channel) {
$this->flush($channel, 0);
$channel->close();
}
static::$_connections = [];
$this->creates = -1;
} else {
$this->heartbeat_flush();
@@ -131,7 +136,6 @@ class ClientsPool extends Component
public function flush($channel, $retain_number)
{
$this->pop($channel, $retain_number);
static::$_connections = [];
}
@@ -180,12 +184,16 @@ class ClientsPool extends Component
* @param $name
* @return Channel
* @throws ConfigException
* @throws Exception
*/
private function getChannel($name): Channel
{
if (!isset(static::$_connections[$name])) {
static::$_connections[$name] = new Channel(Config::get('databases.pool.max', 10));
}
if (static::$_connections[$name]->errCode == SWOOLE_CHANNEL_CLOSED){
throw new Exception('Channel is Close.');
}
if ($this->creates === -1) {
$this->creates = Timer::tick(60000, [$this, 'Heartbeat_detection']);
}