Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 73cb94f657 | |||
| b3ea8978b1 | |||
| 008a0914eb | |||
| 01f8e16b38 | |||
| c095b69f67 | |||
| 4c8c5ac239 | |||
| cfc847133e | |||
| 30b430f1cf | |||
| 516c7612a5 | |||
| 3bb3d5a1d7 |
@@ -22,7 +22,7 @@ abstract class HttpService extends Component
|
||||
* @param string $category
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function write($message, $category = 'app')
|
||||
protected function write($message, string $category = 'app')
|
||||
{
|
||||
$logger = Snowflake::app()->getLogger();
|
||||
$logger->write($message, $category);
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -35,7 +35,6 @@ use function Co\run;
|
||||
* @package Snowflake
|
||||
*
|
||||
* @property-read Config $config
|
||||
* @property-read WchatProviders $wchat
|
||||
*/
|
||||
class Application extends BaseApplication
|
||||
{
|
||||
@@ -62,6 +61,9 @@ class Application extends BaseApplication
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param Closure|array $closure
|
||||
* @return $this
|
||||
|
||||
+14
-14
@@ -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
@@ -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
|
||||
*
|
||||
|
||||
@@ -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']);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ abstract class Process extends \Swoole\Process implements SProcess
|
||||
|
||||
fire(Event::SERVER_WORKER_START);
|
||||
if (Snowflake::getPlatform()->isLinux()) {
|
||||
swoole_set_process_name($this->getProcessName());
|
||||
name($this->pid, $this->getProcessName());
|
||||
}
|
||||
if (method_exists($this, 'before')) {
|
||||
$this->before($process);
|
||||
|
||||
Reference in New Issue
Block a user