改名
This commit is contained in:
@@ -7,6 +7,7 @@ namespace Http\Route;
|
|||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Http\Context\Context;
|
||||||
use Http\Exception\RequestException;
|
use Http\Exception\RequestException;
|
||||||
use JetBrains\PhpStorm\Pure;
|
use JetBrains\PhpStorm\Pure;
|
||||||
use Kiri\Events\EventProvider;
|
use Kiri\Events\EventProvider;
|
||||||
@@ -14,8 +15,8 @@ use Kiri\Exception\NotFindClassException;
|
|||||||
use Kiri\Kiri;
|
use Kiri\Kiri;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Server\Constant;
|
use Server\Constant;
|
||||||
use Server\Events\OnAfterWorkerStart;
|
|
||||||
use Server\Constrict\RequestInterface;
|
use Server\Constrict\RequestInterface;
|
||||||
|
use Server\Events\OnAfterWorkerStart;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Node
|
* Class Node
|
||||||
|
|||||||
@@ -57,11 +57,11 @@ class Request implements RequestInterface
|
|||||||
{
|
{
|
||||||
$serverRequest = ServerRequest::createServerRequest($request);
|
$serverRequest = ServerRequest::createServerRequest($request);
|
||||||
|
|
||||||
Context::setContext(ResponseInterface::class, $response = new Response());
|
Context::setContext(ResponseInterface::class, new Response());
|
||||||
|
|
||||||
Context::setContext(RequestInterface::class, $serverRequest);
|
Context::setContext(RequestInterface::class, $serverRequest);
|
||||||
|
|
||||||
return [Kiri::getDi()->get(Request::class), $response];
|
return Kiri::getDi()->get(Request::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use Http\Exception\RequestException;
|
|||||||
use Http\Route\Node;
|
use Http\Route\Node;
|
||||||
use Kiri\Core\Help;
|
use Kiri\Core\Help;
|
||||||
use Server\Constant;
|
use Server\Constant;
|
||||||
use Server\Constrict\RequestInterface;
|
use Server\Constrict\Request as ScRequest;
|
||||||
use Server\Constrict\ResponseInterface;
|
use Server\Constrict\ResponseInterface;
|
||||||
use Server\Events\OnAfterRequest;
|
use Server\Events\OnAfterRequest;
|
||||||
use Server\SInterface\OnClose;
|
use Server\SInterface\OnClose;
|
||||||
@@ -42,22 +42,16 @@ class Http extends \Server\Abstracts\Http implements OnClose, OnConnect
|
|||||||
public function onRequest(Request $request, Response $response): void
|
public function onRequest(Request $request, Response $response): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
[$request, $psr7Response] = \Server\Constrict\Request::create($request);
|
$node = $this->router->Branch_search($Psr7Request = ScRequest::create($request));
|
||||||
/** @var RequestInterface $request */
|
|
||||||
$node = $this->router->Branch_search($request);
|
|
||||||
if (!($node instanceof Node)) {
|
if (!($node instanceof Node)) {
|
||||||
throw new RequestException(Constant::STATUS_404_MESSAGE, 404);
|
throw new RequestException(Constant::STATUS_404_MESSAGE, 404);
|
||||||
}
|
}
|
||||||
$psr7Response = $node->dispatch($request);
|
if (!(($psr7Response = $node->dispatch($Psr7Request)) instanceof ResponseInterface)) {
|
||||||
if (!($psr7Response instanceof ResponseInterface)) {
|
|
||||||
$psr7Response = $this->transferToResponse($psr7Response);
|
$psr7Response = $this->transferToResponse($psr7Response);
|
||||||
}
|
}
|
||||||
} catch (Error | \Throwable $exception) {
|
} catch (Error | \Throwable $exception) {
|
||||||
$psr7Response = $this->exceptionHandler->emit($exception, $this->response);
|
$psr7Response = $this->exceptionHandler->emit($exception, $this->response);
|
||||||
} finally {
|
} finally {
|
||||||
if (!isset($psr7Response)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->responseEmitter->sender($response, $psr7Response);
|
$this->responseEmitter->sender($response, $psr7Response);
|
||||||
$this->eventDispatch->dispatch(new OnAfterRequest());
|
$this->eventDispatch->dispatch(new OnAfterRequest());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user