2025-04-13 19:03:41 +01:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
use Controllers\TaskController;
|
|
|
|
use DI\Bridge\Slim\Bridge;
|
|
|
|
use DI\Container;
|
|
|
|
use Controllers\HomeFrontController;
|
2025-04-16 18:51:53 +01:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
use Psr\Http\Server\RequestHandlerInterface;
|
2025-04-14 00:05:48 +01:00
|
|
|
use Slim\Handlers\Strategies\RequestResponseArgs;
|
2025-04-13 19:03:41 +01:00
|
|
|
|
2025-04-14 15:20:12 +01:00
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
2025-04-13 19:03:41 +01:00
|
|
|
|
|
|
|
$container = new Container();
|
|
|
|
$app = Bridge::create($container);
|
2025-04-16 18:51:53 +01:00
|
|
|
|
2025-04-13 19:03:41 +01:00
|
|
|
$app->addBodyParsingMiddleware();
|
2025-04-16 18:51:53 +01:00
|
|
|
$app->addRoutingMiddleware();
|
|
|
|
$app->addErrorMiddleware(true, true, true);
|
2025-04-13 19:03:41 +01:00
|
|
|
|
2025-04-14 00:05:48 +01:00
|
|
|
// this strategy is preferable because we aren't using a lot of named placeholders
|
|
|
|
$routeCollector = $app->getRouteCollector();
|
|
|
|
$routeCollector->setDefaultInvocationStrategy(new RequestResponseArgs());
|
|
|
|
|
|
|
|
|
2025-04-16 18:51:53 +01:00
|
|
|
$app->add(function (ServerRequestInterface $request, RequestHandlerInterface $handler) use ($app): ResponseInterface {
|
|
|
|
if ($request->getMethod() === 'OPTIONS') {
|
|
|
|
$response = $app->getResponseFactory()->createResponse();
|
|
|
|
} else {
|
|
|
|
$response = $handler->handle($request);
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = $response
|
|
|
|
->withHeader('Access-Control-Allow-Credentials', 'true')
|
|
|
|
->withHeader('Access-Control-Allow-Origin', '*')
|
|
|
|
->withHeader('Access-Control-Allow-Headers', '*')
|
|
|
|
->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS')
|
|
|
|
->withHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
|
|
|
|
->withHeader('Pragma', 'no-cache');
|
|
|
|
|
|
|
|
if (ob_get_contents()) {
|
|
|
|
ob_clean();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
});
|
|
|
|
|
2025-04-13 19:03:41 +01:00
|
|
|
$app->get('/', [HomeFrontController::class, 'home']);
|
|
|
|
|
2025-04-14 00:25:18 +01:00
|
|
|
|
2025-04-14 00:05:48 +01:00
|
|
|
$app->get('/tasks/{id}', [TaskController::class, 'getTask']);
|
2025-04-14 00:25:18 +01:00
|
|
|
$app->delete('/tasks/{id}', [TaskController::class, 'delete']);
|
2025-04-16 15:33:13 +01:00
|
|
|
$app->patch('/tasks/{id}', [TaskController::class, 'update']);
|
2025-04-14 00:25:18 +01:00
|
|
|
|
2025-04-16 16:06:19 +01:00
|
|
|
$app->patch('/tasks/{id}/status/update', [TaskController::class, 'updateStatus']);
|
|
|
|
|
2025-04-14 00:25:18 +01:00
|
|
|
$app->get('/tasks', [TaskController::class, 'getTasks']);
|
2025-04-13 19:03:41 +01:00
|
|
|
$app->post('/tasks', [TaskController::class, 'addTask']);
|
|
|
|
|
2025-04-13 22:18:14 +01:00
|
|
|
|
2025-04-13 19:03:41 +01:00
|
|
|
$app->run();
|