feat(api): 增加了可以使用中间件定制是否 restful 的逻辑

This commit is contained in:
李东云
2023-03-13 11:00:16 +08:00
parent 2d2148f3ec
commit b8c3d6d068
2 changed files with 4 additions and 1 deletions

View File

@@ -11,10 +11,11 @@ namespace Singularity\HDK\Core\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Singularity\HDK\Core\Service\ApiStyleService;
class ClassicStyleMiddleware implements \Psr\Http\Server\MiddlewareInterface
class ClassicStyleMiddleware implements MiddlewareInterface
{
public function __construct(protected ApiStyleService $apiStyleService)
{
@@ -26,5 +27,6 @@ class ClassicStyleMiddleware implements \Psr\Http\Server\MiddlewareInterface
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$this->apiStyleService->set(ApiStyleService::CLASSIC);
return $handler->handle($request);
}
}

View File

@@ -27,5 +27,6 @@ class RestStyleMiddleware implements MiddlewareInterface
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$this->apiStyleService->set(ApiStyleService::RESTFUL);
return $handler->handle($request);
}
}