feat : admin driver name

This commit is contained in:
2024-11-11 13:06:07 +08:00
parent 3aba37d426
commit b64d2872ac
10 changed files with 153 additions and 6 deletions

View 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)));
}
}