bindAPI/bindAPI/public/index.php

39 lines
1.0 KiB
PHP
Raw Normal View History

2022-01-18 19:14:24 +01:00
<?php
require '../vendor/autoload.php';
use App\Controller\DatabaseConnection;
use App\Controller\RequestController;
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");
$dbConnection = (new DatabaseConnection())->getConnection();
// TODO make a log class
$oFile = fopen ('log.txt', 'a');
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
fputs($oFile, $uri);
$uri = explode( '/', $uri );
if ($uri[1] !== 'api') {
header("HTTP/1.1 404 Not Found");
exit();
}
// TODO check for valid API key
$requestMethod = $_SERVER["REQUEST_METHOD"];
// pass the request method and user ID to the PersonController and process the HTTP request:
$controller = new RequestController($dbConnection, $requestMethod, $uri);
$controller->processRequest();
fclose($oFile);