-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.php
44 lines (35 loc) · 1.18 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
use Flashpoint\Controllers\Error404;
use Flashpoint\Controllers\Rooter;
use Flashpoint\Models\Translator;
//Define and set autoloader for custom classes
function autoloader(string $name): void
{
//Replace '\' (used in namespaces) with '/' (used to navigate through directories)
$name = str_replace('\\', '/', $name);
//Remove the root folder from the path (this file is already in it)
if (strpos($name, '/') !== false) {
$name = substr($name, strpos($name, '/') + 1);
}
$name .= '.php';
require $name;
}
spl_autoload_register('autoloader');
//Set character encoding
mb_internal_encoding('UTF-8');
$requestedUrl = $_SERVER['REQUEST_URI'];
//Process the request
$rooter = new Rooter();
$result = $rooter->process(array($requestedUrl));
if ($result !== true) {
//Display the error webpage, overwrite the page headers (title, description, keywords)
$rooter->process(array('err404'));
http_response_code(404);
}
//Function for inserting translations into views
function t(string $key, string ...$formatTags) {
return Translator::translate($key, ...$formatTags);
}
//Display the generated website
$website = $rooter->displayView();
echo $website;