67 lines
1.7 KiB
PHP
67 lines
1.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require __DIR__ . '/../src/Autoloader.php';
|
|
|
|
$autoloader = new Autoloader('App', __DIR__ . '/../src');
|
|
$autoloader->register();
|
|
|
|
$config = require __DIR__ . '/../config/config.php';
|
|
|
|
if ($config['error_reporting']) {
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', '1');
|
|
}
|
|
|
|
header('Access-Control-Allow-Origin: ' . $config['cors']['allow_origin']);
|
|
header('Access-Control-Allow-Methods: ' . $config['cors']['allow_methods']);
|
|
header('Access-Control-Allow-Headers: ' . $config['cors']['allow_headers']);
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
|
http_response_code(204);
|
|
exit;
|
|
}
|
|
|
|
use App\Database;
|
|
use App\Router;
|
|
use App\Controllers\ListController;
|
|
use App\Controllers\ItemController;
|
|
|
|
Database::init($config['db']['path']);
|
|
|
|
$router = new Router();
|
|
|
|
$router->addRoute('POST', '/list', function () {
|
|
ListController::create();
|
|
});
|
|
|
|
$router->addRoute('GET', '/list/{uuid}', function (string $uuid) {
|
|
ListController::show($uuid);
|
|
});
|
|
|
|
$router->addRoute('PATCH', '/list/{uuid}', function (string $uuid) {
|
|
ListController::update($uuid);
|
|
});
|
|
|
|
$router->addRoute('DELETE', '/list/{uuid}', function (string $uuid) {
|
|
ListController::delete($uuid);
|
|
});
|
|
|
|
$router->addRoute('POST', '/list/{uuid}/item', function (string $uuid) {
|
|
ItemController::create($uuid);
|
|
});
|
|
|
|
$router->addRoute('PATCH', '/list/{uuid}/item/{id}', function (string $uuid, string $id) {
|
|
ItemController::update($uuid, $id);
|
|
});
|
|
|
|
$router->addRoute('DELETE', '/list/{uuid}/item/{id}', function (string $uuid, string $id) {
|
|
ItemController::delete($uuid, $id);
|
|
});
|
|
|
|
try {
|
|
$router->dispatch($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
|
|
} catch (Exception $e) {
|
|
Router::sendResponse(['error' => 'Internal server error'], 500);
|
|
}
|