Selecteur du controlleur depuis l'URL[1] réalisé. Si non ok, alors affichage de toutes les possiblitées.

This commit is contained in:
Cédric Abonnel 2022-12-29 23:25:42 +01:00
parent 7b996cc5f6
commit 4caafe16d5
1 changed files with 20 additions and 4 deletions

View File

@ -1,4 +1,8 @@
<?php <?php
require "../bootstrap.php"; require "../bootstrap.php";
use Src\Controller\CompteurController; use Src\Controller\CompteurController;
@ -18,10 +22,13 @@ $endpoints = array(
'compteur', 'compteur',
'releve' 'releve'
); );
/*
if ( ! in_array($uri[1], $endpoints) ) { if ( ! in_array($uri[1], $endpoints) ) {
header("HTTP/1.1 404 Not Found"); header("HTTP/1.1 404 Not Found");
exit(); exit();
} }
*/
// the user id is, of course, optional and must be a number: // the user id is, of course, optional and must be a number:
$id = null; $id = null;
@ -31,9 +38,18 @@ if (isset($uri[2])) {
$requestMethod = $_SERVER["REQUEST_METHOD"]; $requestMethod = $_SERVER["REQUEST_METHOD"];
// pass the request method and user ID to the CompteurController and process the HTTP request: switch($uri[1]) {
$qsd = CompteurController case 'compteur':
$controller = new $qsd($dbConnection, $requestMethod, $id); $controller = new CompteurController($dbConnection, $requestMethod, $id);
$controller->processRequest(); $controller->processRequest();
break;
case 'releve':
break;
default:
echo json_encode($endpoints);
break;
}