eee
This commit is contained in:
@@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Kiri\Router\Annotate;
|
|
||||||
|
|
||||||
use Kiri\Router\ContentType;
|
|
||||||
|
|
||||||
#[\Attribute(\Attribute::TARGET_METHOD)]
|
|
||||||
class ResponseContentType
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ContentType $contentType
|
|
||||||
*/
|
|
||||||
public function __construct(public ContentType $contentType = ContentType::JSON)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -12,33 +12,40 @@ abstract class AbstractHandler
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public int $offset = 0;
|
public int $offset = 0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $middlewares
|
* @param array $middlewares
|
||||||
* @param Handler $handler
|
* @param Handler $handler
|
||||||
* @throws
|
*
|
||||||
*/
|
* @throws
|
||||||
public function __construct(public array $middlewares, public Handler $handler)
|
*/
|
||||||
{
|
public function __construct(public array $middlewares, public Handler $handler)
|
||||||
}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ServerRequestInterface $request
|
|
||||||
* @return ResponseInterface
|
|
||||||
* @throws
|
|
||||||
*/
|
|
||||||
public function execute(ServerRequestInterface $request): ResponseInterface
|
|
||||||
{
|
|
||||||
if (!isset($this->middlewares[$this->offset])) {
|
|
||||||
return $this->handler->handle($request);
|
|
||||||
}
|
|
||||||
|
|
||||||
$middleware = $this->middlewares[$this->offset];
|
/**
|
||||||
$this->offset += 1;
|
* @param ServerRequestInterface $request
|
||||||
|
*
|
||||||
|
* @return ResponseInterface
|
||||||
|
* @throws
|
||||||
|
*/
|
||||||
|
public function execute(ServerRequestInterface $request): ResponseInterface
|
||||||
|
{
|
||||||
|
if (!isset($this->middlewares[$this->offset])) {
|
||||||
|
return $this->handler->handle($request);
|
||||||
|
}
|
||||||
|
|
||||||
return ($middleware instanceof MiddlewareInterface ? $middleware : di($middleware))->process($request, $this);
|
$middleware = $this->middlewares[$this->offset];
|
||||||
}
|
$this->offset += 1;
|
||||||
|
|
||||||
|
if (!($middleware instanceof MiddlewareInterface)) {
|
||||||
|
$middleware = \Kiri::getDi()->get($middleware);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $middleware->process($request, $this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user