ouii
continuous-integration/drone/push Build encountered an error Details

WORK-DDA
David D'ALMEIDA 2 years ago
parent ce4411500a
commit d429a53b2d

@ -6,12 +6,12 @@ class App
private static $instance; private static $instance;
private Router $router; private Router $router;
private Connection $dataBase; private Connection $dataBase;
private FrontController $frontController;
private function __construct() private function __construct()
{ {
$this->router = new Router(); $this->router = new Router();
$this->frontController = new FrontController($this->router);
} }
public static function getInstance() public static function getInstance()
@ -22,14 +22,9 @@ class App
return self::$instance; return self::$instance;
} }
public function getRouter()
{
return $this->router;
}
public function run() public function run()
{ {
$this->frontController->dispatch();
} }
} }

@ -0,0 +1,44 @@
<?php
// FrontController.php
class FrontController {
private $router;
public function __construct(Router $router) {
$this->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";
}
}
?>
Loading…
Cancel
Save