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.
Application-Web/public/index.php

37 lines
978 B

<?php
require "../vendor/autoload.php";
require "../config.php";
use App\Controller\SampleFormController;
/**
* relative path of the index.php's directory from the server's document root.
*/
global $basePath;
// find the server path of the index.php file
$basePath = dirname(substr(__FILE__, strlen($_SERVER['DOCUMENT_ROOT'])));
if ($basePath[strlen($basePath) - 1] == "/") {
$basePath = substr($basePath, 0, strlen($basePath) - 1);
}
// routes initialization
$router = new AltoRouter();
$router->setBasePath($basePath);
$sampleFormController = new SampleFormController();
$router->map("GET", "/", fn() => $sampleFormController->displayForm());
$router->map("POST", "/result", fn() => $sampleFormController->displayResults($_POST));
$match = $router->match();
if ($match == null) {
// TODO redirect to a 404 not found page instead (issue #1)
echo "page non trouvée";
header('HTTP/1.1 404 Not Found');
exit(1);
}
call_user_func($match['target']);