feat : admin driver name
This commit is contained in:
43
app/Middleware/CoreMiddleware.php
Normal file
43
app/Middleware/CoreMiddleware.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Lib\AdminReturn;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpMessage\Stream\SwooleStream;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class CoreMiddleware extends \Hyperf\HttpServer\CoreMiddleware
|
||||
{
|
||||
/**
|
||||
* @var AdminReturn
|
||||
*/
|
||||
#[Inject]
|
||||
protected AdminReturn $return;
|
||||
|
||||
/**
|
||||
* 404重写
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
protected function handleNotFound(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->response()->withHeader("Content-Type", "application/json")
|
||||
->withStatus(200)
|
||||
->withBody(new SwooleStream(json_encode($this->return->error('路由不存在'), JSON_UNESCAPED_UNICODE)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 405重写
|
||||
* @param array $methods
|
||||
* @param ServerRequestInterface $request
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
protected function handleMethodNotAllowed(array $methods, ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->response()->withHeader("Content-Type", "application/json")
|
||||
->withStatus(200)
|
||||
->withBody(new SwooleStream(json_encode($this->return->error('路由请求方法不正确'), JSON_UNESCAPED_UNICODE)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user