27 lines
630 B
PHP
27 lines
630 B
PHP
<?php
|
|
|
|
function route(string $uri, callable $callback) {
|
|
if (urldecode(strtok($_SERVER['REQUEST_URI'], '?')) !== $uri)
|
|
return;
|
|
$callback();
|
|
die();
|
|
}
|
|
|
|
function view(string $_view, array $_data = []) {
|
|
$_path = __DIR__ . '/../view/' . $_view . '.php';
|
|
extract($_data);
|
|
require $_path;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
route('/', fn() =>
|
|
view('home'));
|
|
|
|
http_response_code(404);
|
|
view('404'); |