This commit is contained in:
2024-12-16 16:05:01 +08:00
parent 34ab8f145c
commit daa02a6408
2 changed files with 31 additions and 43 deletions
-19
View File
@@ -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)
{
}
}
+8 -1
View File
@@ -18,14 +18,17 @@ abstract class AbstractHandler
/** /**
* @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 * @param ServerRequestInterface $request
*
* @return ResponseInterface * @return ResponseInterface
* @throws * @throws
*/ */
@@ -38,7 +41,11 @@ abstract class AbstractHandler
$middleware = $this->middlewares[$this->offset]; $middleware = $this->middlewares[$this->offset];
$this->offset += 1; $this->offset += 1;
return ($middleware instanceof MiddlewareInterface ? $middleware : di($middleware))->process($request, $this); if (!($middleware instanceof MiddlewareInterface)) {
$middleware = \Kiri::getDi()->get($middleware);
}
return $middleware->process($request, $this);
} }
} }