2023-03-21 17:23:14 +00:00
|
|
|
<?php
|
2023-08-14 21:03:24 +00:00
|
|
|
|
2023-05-02 00:13:29 +00:00
|
|
|
function route(string $uri, callable $callback) {
|
|
|
|
if (urldecode(strtok($_SERVER['REQUEST_URI'], '?')) !== $uri)
|
|
|
|
return;
|
|
|
|
$callback();
|
|
|
|
die();
|
|
|
|
}
|
2023-03-21 17:23:14 +00:00
|
|
|
|
2023-05-02 00:13:29 +00:00
|
|
|
function view(string $_view, array $_data = []) {
|
|
|
|
$_path = __DIR__ . '/../view/' . $_view . '.php';
|
|
|
|
extract($_data);
|
|
|
|
require $_path;
|
|
|
|
}
|
2023-03-21 17:23:14 +00:00
|
|
|
|
2023-05-02 00:13:29 +00:00
|
|
|
function url(string $url, bool $full = false): string {
|
|
|
|
$dir = dirname($_SERVER['SCRIPT_NAME']);
|
|
|
|
if ($dir === '/') $dir = '';
|
|
|
|
if (!$full) return $dir . $url;
|
|
|
|
return isset($_SERVER['HTTPS']) ? 'https' : 'http' . '://' . $_SERVER['HTTP_HOST'] . $dir . $url;
|
|
|
|
}
|
2023-03-21 17:23:14 +00:00
|
|
|
|
2023-05-02 00:13:29 +00:00
|
|
|
route('/', fn() =>
|
|
|
|
view('home'));
|
2023-03-21 17:23:14 +00:00
|
|
|
|
|
|
|
http_response_code(404);
|
|
|
|
view('404');
|