changed PDO to DatabaseConnection
Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
parent
c0ac072bb3
commit
5336a0bde8
@ -1,42 +1,40 @@
|
||||
<?php
|
||||
namespace App\Controller;
|
||||
|
||||
require '../vendor/autoload.php';
|
||||
// 61eec33c8829a.91a1d27d70ba26710092381a073d9e546597dff6033de272
|
||||
require dirname(path: __DIR__) . '/vendor/autoload.php';
|
||||
|
||||
// read config
|
||||
$configFile = dirname(__DIR__) . "/config.json";
|
||||
$configFile = dirname(path: __DIR__) . "/config.json";
|
||||
$configJSON = file_get_contents($configFile);
|
||||
$config = json_decode($configJSON, associative: true);
|
||||
|
||||
|
||||
use App\Controller\DatabaseConnection;
|
||||
use App\Controller\RequestController;
|
||||
|
||||
|
||||
// TODO only valid clients?
|
||||
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");
|
||||
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");
|
||||
|
||||
|
||||
|
||||
// TODO make a log class
|
||||
$oFile = fopen ('log.txt', 'a');
|
||||
$oFile = fopen (filename: 'log.txt', mode: 'a');
|
||||
|
||||
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
fputs($oFile, $uri . PHP_EOL);
|
||||
fclose($oFile);
|
||||
$uri = parse_url(url: $_SERVER['REQUEST_URI'], component: PHP_URL_PATH);
|
||||
fputs(stream: $oFile, data: $uri . PHP_EOL);
|
||||
fclose(stream: $oFile);
|
||||
|
||||
$uri = explode( '/', $uri );
|
||||
$uri = explode( separator: '/', string: $uri );
|
||||
if ($uri[1] !== 'api') {
|
||||
header("HTTP/1.1 404 Not Found");
|
||||
header(header: "HTTP/1.1 404 Not Found");
|
||||
exit();
|
||||
}
|
||||
|
||||
$requestMethod = $_SERVER["REQUEST_METHOD"];
|
||||
$dbConnection = (new DatabaseConnection(config: $config))->getConnection();
|
||||
$databaseConnection = new DatabaseConnection(config: $config);
|
||||
|
||||
$controller = new RequestController($dbConnection, $requestMethod, $uri);
|
||||
$controller = new RequestController(databaseConnection: $databaseConnection, requestMethod: $requestMethod, uri: $uri);
|
||||
$controller->processRequest();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user