diff --git a/Sources/src/app/App.php b/Sources/src/app/App.php index 61411eda..0ce8bb08 100644 --- a/Sources/src/app/App.php +++ b/Sources/src/app/App.php @@ -6,12 +6,12 @@ class App private static $instance; private Router $router; private Connection $dataBase; - + private FrontController $frontController; private function __construct() { - $this->router = new Router(); + $this->frontController = new FrontController($this->router); } public static function getInstance() @@ -22,14 +22,9 @@ class App return self::$instance; } - public function getRouter() - { - return $this->router; - } - public function run() { - + $this->frontController->dispatch(); } } diff --git a/Sources/src/app/controller/FrontController.php b/Sources/src/app/controller/FrontController.php new file mode 100644 index 00000000..8502af0d --- /dev/null +++ b/Sources/src/app/controller/FrontController.php @@ -0,0 +1,44 @@ +router = $router; + } + + public function dispatch() { + $match = $this->router->match(); + + if ($match) { + $controllerName = $match['controller']; + $actionName = $match['action']; + + // Utilisez l'injection de dépendances pour créer le contrôleur + $controller = $this->createController($controllerName); + + if ($controller) { + // Appeler l'action correspondante + $controller->$actionName(); + } else { + // Gérer l'erreur, le contrôleur n'existe pas + $this->handleError(); + } + } else { + // Gérer l'erreur, aucune route correspondante + $this->handleError(); + } + } + + private function createController($controllerName) { + // Utilisez un conteneur d'injection de dépendances pour créer le contrôleur + return DependencyContainer::create($controllerName); + } + + private function handleError() { + header("HTTP/1.0 404 Not Found"); + echo "Page not found"; + } +} + +?> \ No newline at end of file