初始化
parent
7dafc96462
commit
2a7e886a70
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace App\Bootstrap;
|
||||
|
||||
use App\Service\SocketFDService;
|
||||
use Hyperf\Framework\Bootstrap\ServerStartCallback;
|
||||
use Hashids\Hashids;
|
||||
use Swoole\Timer;
|
||||
use Hyperf\Redis\Redis;
|
||||
|
||||
|
|
|
@ -1,23 +1,15 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace App\Exception\Handler;
|
||||
|
||||
use App\Exception\ValidateException;
|
||||
use Hyperf\Contract\StdoutLoggerInterface;
|
||||
use Hyperf\ExceptionHandler\ExceptionHandler;
|
||||
use Hyperf\HttpMessage\Stream\SwooleStream;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Throwable;
|
||||
use Phper666\JWTAuth\Exception\TokenValidException;
|
||||
|
||||
class AppExceptionHandler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
|
@ -32,22 +24,16 @@ class AppExceptionHandler extends ExceptionHandler
|
|||
|
||||
public function handle(Throwable $throwable, ResponseInterface $response)
|
||||
{
|
||||
// 判断是否是验证器异常类
|
||||
if($throwable instanceof ValidateException){
|
||||
return $response;
|
||||
}
|
||||
|
||||
if($throwable instanceof TokenValidException){
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
$this->logger->error(sprintf('%s[%s] in %s', $throwable->getMessage(), $throwable->getLine(), $throwable->getFile()));
|
||||
$this->logger->error($throwable->getTraceAsString());
|
||||
|
||||
return $response->withHeader('Server', 'Hyperf')->withStatus(500)->withBody(new SwooleStream('Internal Server Error.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Throwable $throwable
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid(Throwable $throwable): bool
|
||||
{
|
||||
return true;
|
||||
|
|
|
@ -16,6 +16,8 @@ class JwtAuthExceptionHandler extends ExceptionHandler
|
|||
{
|
||||
public function handle(Throwable $throwable, ResponseInterface $response)
|
||||
{
|
||||
|
||||
// echo $throwable->getMessage();
|
||||
// 判断被捕获到的异常是希望被捕获的异常
|
||||
if ($throwable instanceof TokenValidException) {
|
||||
// 格式化输出
|
||||
|
@ -27,7 +29,6 @@ class JwtAuthExceptionHandler extends ExceptionHandler
|
|||
|
||||
// 阻止异常冒泡
|
||||
$this->stopPropagation();
|
||||
|
||||
return $response->withAddedHeader('content-type', 'application/json; charset=utf-8')->withStatus(401)->withBody(new SwooleStream($data));
|
||||
}
|
||||
|
||||
|
@ -36,6 +37,9 @@ class JwtAuthExceptionHandler extends ExceptionHandler
|
|||
|
||||
/**
|
||||
* 判断该异常处理器是否要对该异常进行处理
|
||||
*
|
||||
* @param Throwable $throwable
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid(Throwable $throwable): bool
|
||||
{
|
||||
|
|
|
@ -16,6 +16,11 @@ use Throwable;
|
|||
*/
|
||||
class ValidateExceptionHandler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* @param Throwable $throwable
|
||||
* @param ResponseInterface $response
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function handle(Throwable $throwable, ResponseInterface $response)
|
||||
{
|
||||
// 判断被捕获到的异常是希望被捕获的异常
|
||||
|
@ -38,6 +43,9 @@ class ValidateExceptionHandler extends ExceptionHandler
|
|||
|
||||
/**
|
||||
* 判断该异常处理器是否要对该异常进行处理
|
||||
*
|
||||
* @param Throwable $throwable
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid(Throwable $throwable): bool
|
||||
{
|
||||
|
|
|
@ -10,7 +10,7 @@ class Hash
|
|||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public static function make($value)
|
||||
public static function make(string $value)
|
||||
{
|
||||
return password_hash($value, PASSWORD_DEFAULT);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class Hash
|
|||
* @param string $hashedValue
|
||||
* @return bool
|
||||
*/
|
||||
public static function check($value, $hashedValue)
|
||||
public static function check(string $value, string $hashedValue)
|
||||
{
|
||||
return password_verify($value, $hashedValue);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ class DbQueryExecutedListener implements ListenerInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* @param QueryExecuted $event
|
||||
* @param object|QueryExecuted $event
|
||||
*/
|
||||
public function process(object $event)
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@ class Response
|
|||
* @Inject
|
||||
* @var ResponseInterface|mixed
|
||||
*/
|
||||
protected $response;
|
||||
private $response;
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
|
|
|
@ -13,9 +13,9 @@ return [
|
|||
'handler' => [
|
||||
'http' => [
|
||||
Hyperf\HttpServer\Exception\Handler\HttpExceptionHandler::class,
|
||||
App\Exception\Handler\AppExceptionHandler::class,
|
||||
App\Exception\Handler\ValidateExceptionHandler::class,
|
||||
App\Exception\Handler\JwtAuthExceptionHandler::class,
|
||||
App\Exception\Handler\ValidateExceptionHandler::class,
|
||||
App\Exception\Handler\AppExceptionHandler::class,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue