api.ampere/public/index.php

56 lines
1.2 KiB
PHP
Raw Normal View History

2022-12-29 22:25:38 +01:00
<?php
2022-12-29 22:25:38 +01:00
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'
);
/*
2022-12-29 22:25:38 +01:00
if ( ! in_array($uri[1], $endpoints) ) {
header("HTTP/1.1 404 Not Found");
exit();
}
*/
2022-12-29 22:25:38 +01:00
// 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"];
switch($uri[1]) {
case 'compteur':
$controller = new CompteurController($dbConnection, $requestMethod, $id);
$controller->processRequest();
break;
case 'releve':
break;
default:
echo json_encode($endpoints);
break;
}
2022-12-29 22:25:38 +01:00