Add bootstrap factory for framework loading

This commit is contained in:
Maarten 2024-11-26 14:20:46 +01:00
parent ab5fa6d69e
commit 83bc1a1661
11 changed files with 254 additions and 45 deletions

View file

@ -2,8 +2,7 @@
namespace Core\Routing;
use Core\Env\Env;
use Core\Exceptions\Exceptions;
use Core\Exceptions\ExceptionHandler;
use Core\Exceptions\Exceptions\NotFoundHttpException;
use Core\Http\Request;
use Core\View\Render;
@ -26,10 +25,13 @@ class RouteDispatcher
private array $routeCollection;
/**
* Dispatch the router dispatcher
*
* @param \Core\Http\Request $request
* @param array $routeCollection
* @return void
*/
public function __construct(Request $request, array $routeCollection)
public function dispatch(Request $request, array $routeCollection): void
{
$this->request = $request;
$this->routeCollection = $routeCollection;
@ -48,18 +50,6 @@ class RouteDispatcher
}
}
/**
* Dispatch the router dispatcher
*
* @param \Core\Http\Request $request
* @param array $routeCollection
* @return void
*/
public static function dispatch(Request $request, array $routeCollection): void
{
new self($request, $routeCollection);
}
/**
* Locate a matching route for the incoming request.
*
@ -153,8 +143,8 @@ class RouteDispatcher
*/
private function handleException(Exception $e, int $statusCode, string $message): void
{
if (Env::get('debug')) {
Exceptions::catchOne($e);
if (env('debug')) {
ExceptionHandler::catchOne($e);
}
http_response_code($statusCode);