Files
kiri-core/http-server/Abstracts/Http.php
T

54 lines
1.1 KiB
PHP
Raw Normal View History

2021-08-12 12:40:06 +08:00
<?php
namespace Server\Abstracts;
use Annotation\Inject;
2021-08-17 16:43:50 +08:00
use Http\Route\Router;
2021-08-12 12:40:06 +08:00
use Kiri\Abstracts\Config;
use Kiri\Exception\ConfigException;
use Kiri\Exception\NotFindClassException;
use Kiri\Kiri;
use ReflectionException;
2021-08-12 15:07:12 +08:00
use Server\Constrict\ResponseEmitter;
use Server\Constrict\TcpEmitter;
2021-08-12 12:40:06 +08:00
use Server\ExceptionHandlerDispatcher;
use Server\ExceptionHandlerInterface;
use Server\SInterface\OnRequest;
/**
*
*/
2021-08-12 14:00:44 +08:00
abstract class Http extends Server implements OnRequest
2021-08-12 12:40:06 +08:00
{
use EventDispatchHelper;
use ResponseHelper;
/** @var Router|mixed */
2021-09-07 14:01:50 +08:00
#[Inject(Router::class)]
2021-08-12 12:40:06 +08:00
public Router $router;
/**
* @var ExceptionHandlerInterface
*/
public ExceptionHandlerInterface $exceptionHandler;
/**
* @throws ConfigException
*/
public function init()
{
$exceptionHandler = Config::get('exception.http', ExceptionHandlerDispatcher::class);
if (!in_array(ExceptionHandlerInterface::class, class_implements($exceptionHandler))) {
$exceptionHandler = ExceptionHandlerDispatcher::class;
}
$this->exceptionHandler = Kiri::getDi()->get($exceptionHandler);
2021-08-12 15:07:12 +08:00
$this->responseEmitter = Kiri::getDi()->get(ResponseEmitter::class);
2021-08-12 12:40:06 +08:00
}
}