diff --git a/src/Ardeidae.php b/src/Ardeidae.php index 7890a472232f2683d7c8eb01a4f17dd64d2a5bc8..b934bc24e5cfa49678b9b8a3e3a31bbe06f5b1f6 100644 --- a/src/Ardeidae.php +++ b/src/Ardeidae.php @@ -45,9 +45,11 @@ abstract class Ardeidae { $this -> Basis = $this -> getBasis(); /** - * Construct a kernel + * Construct and register the Kernel */ $this -> Kernel = $this -> getKernel(); + $this -> Basis -> inject($this -> Kernel); + $this -> Basis -> registerWire(Kernel::CLASS, get_class($this -> Kernel)); /** * Call the bootstrap method diff --git a/src/Http/Kernel.php b/src/Http/Kernel.php index 0fae05f5c16f1008cba8e852ca44c75788086625..1923c3c522974e51885f59ed4f2ac96ea31e8e34 100644 --- a/src/Http/Kernel.php +++ b/src/Http/Kernel.php @@ -74,10 +74,28 @@ final class Kernel implements KernelInterface { */ public function exec() : void { + /** + * Call the endpoint + */ + $response = $this -> callRequest($this -> Request); + + /** + * Send the response! + */ + $response -> send(); + + } + + + /** + * Make a call to a given Request and get the endpoint's Response. + */ + public function callRequest(Request $Request) : Response { + /** * Get our `Endpoint` */ - $endpoint = $this -> routeRequest(); + $endpoint = $this -> routeRequest($this -> Request); /** * Discover method's middleware (Request Layers) @@ -104,10 +122,7 @@ final class Kernel implements KernelInterface { */ $response = ($createMiddlewareRequestLayer(0) ?? $this -> RequestHandler) -> handle($endpoint); - /** - * Send the response! - */ - $response -> send(); + return $response; } @@ -163,9 +178,7 @@ final class Kernel implements KernelInterface { * * When there's no match we use our default 404 handler. */ - public function routeRequest() : Endpoint { - - $request = $this -> Request; + public function routeRequest(Request $Request) : Endpoint { foreach ($this -> Controllers as $cntrl) { foreach ((new \ReflectionClass($cntrl)) -> getMethods() as $mth) { @@ -173,12 +186,12 @@ final class Kernel implements KernelInterface { $route = $attr -> newInstance(); - if ($this -> Router -> match($request, $route)) { + if ($this -> Router -> match($Request, $route)) { return new Endpoint( - $request, + $Request, $mth, $this -> Router -> getUriParameters( - $request -> getUri(), + $Request -> getUri(), $route -> getUri() ) ); @@ -189,7 +202,7 @@ final class Kernel implements KernelInterface { } return new Endpoint( - $request, + $Request, new \ReflectionMethod(RequestHandler404::CLASS, "handle") );