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.
47 lines
1.2 KiB
47 lines
1.2 KiB
<?php
|
|
|
|
require "../vendor/autoload.php";
|
|
require "../config.php";
|
|
require "../sql/database.php";
|
|
|
|
use App\Connexion;
|
|
use App\Controller\SampleFormController;
|
|
use App\Gateway\FormResultGateway;
|
|
|
|
/**
|
|
* relative path of the index.php's directory from the server's document root.
|
|
*/
|
|
function get_base_path() {
|
|
// find the server path of the index.php file
|
|
$basePath = dirname(substr(__FILE__, strlen($_SERVER['DOCUMENT_ROOT'])));
|
|
|
|
$c = $basePath[strlen($basePath) - 1];
|
|
|
|
if ($c == "/" || $c == "\\") {
|
|
$basePath = substr($basePath, 0, strlen($basePath) - 1);
|
|
}
|
|
return $basePath;
|
|
}
|
|
|
|
$basePath = get_base_path();
|
|
$con = new Connexion(get_database());
|
|
|
|
// routes initialization
|
|
$router = new AltoRouter();
|
|
$router->setBasePath($basePath);
|
|
|
|
$sampleFormController = new SampleFormController(new FormResultGateway($con));
|
|
$router->map("GET", "/", fn() => $sampleFormController->displayForm());
|
|
$router->map("POST", "/submit", fn() => $sampleFormController->submitForm($_POST));
|
|
|
|
$match = $router->match();
|
|
|
|
if ($match == null) {
|
|
// TODO redirect to a 404 not found page instead (issue #1)
|
|
http_response_code(404);
|
|
echo "Page non trouvée";
|
|
exit(1);
|
|
}
|
|
|
|
call_user_func($match['target']);
|