This commit is contained in:
as2252258@163.com
2021-09-24 02:04:36 +08:00
parent 318fe08eb5
commit b9a1178fbe
10 changed files with 168 additions and 237 deletions
+37 -1
View File
@@ -9,17 +9,26 @@ use Http\Handler\Context;
use Http\Handler\Abstracts\HandlerManager;
use Http\Handler\Dispatcher;
use Http\Handler\Handler;
use Http\Handler\Router;
use Http\Message\ContentType;
use Http\Message\ServerRequest;
use Http\Message\Stream;
use Http\Handler\Abstracts\MiddlewareManager;
use Kiri\Abstracts\Config;
use Kiri\Exception\ConfigException;
use Kiri\Kiri;
use Psr\Http\Message\ServerRequestInterface;
use Server\Abstracts\Utility\EventDispatchHelper;
use Server\Abstracts\Utility\ResponseHelper;
use Server\Constrict\RequestInterface;
use Server\Constrict\ResponseEmitter;
use Server\Constrict\ResponseInterface;
use Server\Events\OnAfterRequest;
use Server\ExceptionHandlerDispatcher;
use Server\ExceptionHandlerInterface;
use Server\SInterface\OnClose;
use Server\SInterface\OnConnect;
use Server\SInterface\OnRequest;
use Swoole\Http\Request;
use Swoole\Http\Response;
use Swoole\Server;
@@ -27,9 +36,36 @@ use Swoole\Server;
/**
*
*/
class Http extends \Server\Abstracts\Http implements OnClose, OnConnect
class Http implements OnClose, OnConnect, OnRequest
{
use EventDispatchHelper;
use ResponseHelper;
/** @var Router|mixed */
#[Inject(Router::class)]
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);
$this->responseEmitter = Kiri::getDi()->get(ResponseEmitter::class);
}
/**
* @param Server $server