bindAPI/public/index.php

41 lines
1.3 KiB
PHP
Raw Normal View History

2022-01-18 19:14:24 +01:00
<?php
namespace App\Controller;
2022-01-18 19:14:24 +01:00
// 61eec33c8829a.91a1d27d70ba26710092381a073d9e546597dff6033de272
require dirname(path: __DIR__) . '/vendor/autoload.php';
2022-01-18 19:14:24 +01:00
2022-01-22 17:31:29 +01:00
// read config
$configFile = dirname(path: __DIR__) . "/config.json";
2022-01-22 17:31:29 +01:00
$configJSON = file_get_contents($configFile);
$config = json_decode($configJSON, associative: true);
// TODO only valid clients?
header(header: "Access-Control-Allow-Origin: *");
header(header: "Content-Type: application/json; charset=UTF-8");
header(header: "Access-Control-Allow-Methods: OPTIONS,GET,POST,PUT,DELETE");
header(header: "Access-Control-Max-Age: 3600");
header(header: "Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
2022-01-18 19:14:24 +01:00
// TODO make a log class
$oFile = fopen (filename: 'log.txt', mode: 'a');
2022-01-18 19:14:24 +01:00
$uri = parse_url(url: $_SERVER['REQUEST_URI'], component: PHP_URL_PATH);
fputs(stream: $oFile, data: $uri . PHP_EOL);
fclose(stream: $oFile);
2022-01-18 19:14:24 +01:00
$uri = explode( separator: '/', string: $uri );
2022-01-18 19:14:24 +01:00
if ($uri[1] !== 'api') {
header(header: "HTTP/1.1 404 Not Found");
2022-01-18 19:14:24 +01:00
exit();
}
$requestMethod = $_SERVER["REQUEST_METHOD"];
$databaseConnection = new DatabaseConnection(config: $config);
2022-01-18 19:14:24 +01:00
$controller = new RequestController(databaseConnection: $databaseConnection, requestMethod: $requestMethod, uri: $uri);
2022-01-18 19:14:24 +01:00
$controller->processRequest();