eee
This commit is contained in:
@@ -49,12 +49,4 @@ class Controller extends Kiri\Abstracts\Component
|
|||||||
public ContainerInterface $container;
|
public ContainerInterface $container;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Request $request
|
|
||||||
* @return true
|
|
||||||
*/
|
|
||||||
public function beforeAction(RequestInterface $request): bool
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ use Kiri\Core\Help;
|
|||||||
use Kiri\Router\ContentType;
|
use Kiri\Router\ContentType;
|
||||||
use Kiri\Router\StreamResponse;
|
use Kiri\Router\StreamResponse;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Swoole\Http\Response;
|
|
||||||
|
|
||||||
|
|
||||||
class ConstrictResponse extends Message implements ResponseInterface
|
class ConstrictResponse extends Message implements ResponseInterface
|
||||||
@@ -20,18 +19,11 @@ class ConstrictResponse extends Message implements ResponseInterface
|
|||||||
private string $reasonPhrase;
|
private string $reasonPhrase;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array|mixed
|
|
||||||
*/
|
|
||||||
public array $headers = [];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ContentType|null $contentType
|
* @param ContentType|null $contentType
|
||||||
*/
|
*/
|
||||||
public function __construct(?ContentType $contentType = null)
|
public function __construct(?ContentType $contentType = null)
|
||||||
{
|
{
|
||||||
$this->headers = \config('response.headers', $this->headers);
|
|
||||||
if ($contentType != null) {
|
if ($contentType != null) {
|
||||||
$this->withHeader('Content-Type', $contentType->toString());
|
$this->withHeader('Content-Type', $contentType->toString());
|
||||||
}
|
}
|
||||||
@@ -215,10 +207,6 @@ class ConstrictResponse extends Message implements ResponseInterface
|
|||||||
*/
|
*/
|
||||||
public function end(object $response): void
|
public function end(object $response): void
|
||||||
{
|
{
|
||||||
/** @var Response $response */
|
|
||||||
if (count($this->headers) > 0) foreach ($this->headers as $key => $header) {
|
|
||||||
$response->header($key, $header);
|
|
||||||
}
|
|
||||||
$response->end($this->stream->getContents());
|
$response->end($this->stream->getContents());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ class OnRequest implements OnRequestInterface
|
|||||||
public function onRequest(Request $request, Response $response): void
|
public function onRequest(Request $request, Response $response): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$this->setResponseHeaders($response, $this->response->headers);
|
||||||
|
|
||||||
/** @var CQ $PsrRequest */
|
/** @var CQ $PsrRequest */
|
||||||
Context::set(ResponseInterface::class, new ConstrictResponse($this->response->contentType));
|
Context::set(ResponseInterface::class, new ConstrictResponse($this->response->contentType));
|
||||||
$PsrRequest = Context::set(RequestInterface::class, CQ::builder($request));
|
$PsrRequest = Context::set(RequestInterface::class, CQ::builder($request));
|
||||||
@@ -90,4 +92,17 @@ class OnRequest implements OnRequestInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Response $response
|
||||||
|
* @param array $headers
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function setResponseHeaders(Response $response, array $headers): void
|
||||||
|
{
|
||||||
|
foreach ($headers as $key => $header) {
|
||||||
|
$response->header($key, $header);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,12 @@ class Response implements ResponseInterface
|
|||||||
public ContentType $contentType = ContentType::JSON;
|
public ContentType $contentType = ContentType::JSON;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public array $headers = [];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string|ResponseEmitterInterface
|
* @var string|ResponseEmitterInterface
|
||||||
*/
|
*/
|
||||||
@@ -33,6 +39,7 @@ class Response implements ResponseInterface
|
|||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->contentType = \config('response.content-type', ContentType::JSON);
|
$this->contentType = \config('response.content-type', ContentType::JSON);
|
||||||
|
$this->headers = \config('response.headers', []);
|
||||||
$this->emmit = \config('response.emmit', SwooleHttpResponseEmitter::class);
|
$this->emmit = \config('response.emmit', SwooleHttpResponseEmitter::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user