-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
95 lines (67 loc) · 2.26 KB
/
index.php
File metadata and controls
95 lines (67 loc) · 2.26 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use Twig\TwigFunction;
/**
* Application front controller.
*
* This file boots the framework, configures shared services
* such as Twig and the router, resolves the current route,
* and delegates the request to the matched controller.
*/
// Bootstrap the application and shared services.
require_once __DIR__ . '/core/bootstrap.php';
/*
|--------------------------------------------------------------------------
| Twig configuration
|--------------------------------------------------------------------------
*/
$twigConfiguration = [];
if (PRODUCTION) {
$twigConfiguration = [
'cache' => CACHE_DIR . 'templates',
'auto_reload' => true,
];
} else {
$twigConfiguration = [
'cache' => false,
'auto_reload' => true,
'debug' => true,
];
}
$loader = new FilesystemLoader (__DIR__ . '/templates');
$twig = new Environment ($loader, $twigConfiguration);
// Global template variables.
$twig->addGlobal ('base_url', BASE_URL);
$twig->addGlobal ('version', PRODUCTION ? VERSION : (string) random_int(1, 10000));
// Translation helper.
if (isset ($container['i18n']) && $container['i18n']) {
$twig->addFunction (new TwigFunction('__', function (string $method): string {
try {
return (string) call_user_func('I::' . $method);
} catch (\Throwable $e) {
return '';
}
}));
}
// Store Twig services in the container.
$container['loader'] = $loader;
$container['templates'] = $twig;
/*
|--------------------------------------------------------------------------
| Router configuration
|--------------------------------------------------------------------------
*/
$router = new AltoRouter();
$router->setBasePath(ltrim(BASE_URL, '/'));
$container['router'] = $router;
// Load route definitions.
require_once __DIR__ . '/routes.php';
$match = $router->match();
if ($match && is_callable ($match['target'])) {
$controller = call_user_func_array ($match['target'], $match['params']);
} else {
require __DIR__ . '/controllers/maintenance/NotFound404.php';
$controller = new NotFound404 ();
}
$controller->handle ();