This commit is contained in:
2022-12-15 00:00:32 +01:00
parent 9b344b4e16
commit 01190c5ff2
19 changed files with 230 additions and 66 deletions

52
src/index.php Normal file
View File

@ -0,0 +1,52 @@
<?php
$routes =
[
];
route('/', function () {
echo "Home Page";
});
route('/login', function () {
echo "Login Page";
});
route('/about-us', function () {
echo "About Us";
});
route('/404', function () {
echo "Page not found";
});
function route(string $path, callable $callback) {
global $routes;
$routes[$path] = $callback;
}
run();
function run() {
global $routes;
$uri = $_SERVER['REQUEST_URI'];
$found = false;
foreach ($routes as $path => $callback) {
if ($path !== $uri) continue;
$found = true;
$callback();
}
if (!$found) {
$notFoundCallback = $routes['/404'];
$notFoundCallback();
}
}
?>