first commit
This commit is contained in:
39
public/index.php
Normal file
39
public/index.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
require "../bootstrap.php";
|
||||
use Src\Controller\CompteurController;
|
||||
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Content-Type: application/json; charset=UTF-8");
|
||||
header("Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE");
|
||||
header("Access-Control-Max-Age: 3600");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
|
||||
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
$uri = explode( '/', $uri );
|
||||
|
||||
|
||||
// all of our endpoints start with /???
|
||||
// everything else results in a 404 Not Found
|
||||
$endpoints = array(
|
||||
'compteur',
|
||||
'releve'
|
||||
);
|
||||
if ( ! in_array($uri[1], $endpoints) ) {
|
||||
header("HTTP/1.1 404 Not Found");
|
||||
exit();
|
||||
}
|
||||
|
||||
// the user id is, of course, optional and must be a number:
|
||||
$id = null;
|
||||
if (isset($uri[2])) {
|
||||
$id = (int) $uri[2];
|
||||
}
|
||||
|
||||
$requestMethod = $_SERVER["REQUEST_METHOD"];
|
||||
|
||||
// pass the request method and user ID to the CompteurController and process the HTTP request:
|
||||
$qsd = CompteurController
|
||||
$controller = new $qsd($dbConnection, $requestMethod, $id);
|
||||
$controller->processRequest();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user