You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
43 lines
1.3 KiB
<?php
|
|
|
|
require "../../config.php";
|
|
require "../../vendor/autoload.php";
|
|
require "../../sql/database.php";
|
|
require "../utils.php";
|
|
|
|
use App\Connexion;
|
|
use App\Controller\Api\APITacticController;
|
|
use App\Gateway\TacticInfoGateway;
|
|
use App\Http\JsonHttpResponse;
|
|
use App\Http\ViewHttpResponse;
|
|
use App\Model\TacticModel;
|
|
|
|
$con = new Connexion(get_database());
|
|
|
|
$router = new AltoRouter();
|
|
$router->setBasePath(get_public_path() . "/api");
|
|
|
|
$tacticEndpoint = new APITacticController(new TacticModel(new TacticInfoGateway($con)));
|
|
$router->map("POST", "/tactic/[i:id]/edit/name", fn(int $id) => $tacticEndpoint->updateName($id));
|
|
$router->map("GET", "/tactic/[i:id]", fn(int $id) => $tacticEndpoint->getTacticInfo($id));
|
|
$router->map("POST", "/tactic/new", fn() => $tacticEndpoint->newTactic());
|
|
|
|
$match = $router->match();
|
|
|
|
if ($match == null) {
|
|
echo "404 not found";
|
|
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
|
|
exit(1);
|
|
}
|
|
|
|
$response = call_user_func_array($match['target'], $match['params']);
|
|
|
|
http_response_code($response->getCode());
|
|
|
|
if ($response instanceof JsonHttpResponse) {
|
|
header('Content-type: application/json');
|
|
echo $response->getJson();
|
|
} elseif ($response instanceof ViewHttpResponse) {
|
|
throw new Exception("API returned a view http response.");
|
|
}
|