This repository has been archived by the owner on Oct 29, 2022. It is now read-only.
/
index.php
58 lines (50 loc) · 1.95 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
use Destiny\Common\Application;
use Destiny\Common\ControllerAnnotationLoader;
use Destiny\Common\DirectoryClassIterator;
use Destiny\Common\Log;
use Destiny\Common\Routing\Route;
use Destiny\Common\Routing\Router;
use Destiny\Common\Session\SessionCredentials;
use Destiny\Common\Session\SessionInstance;
use Destiny\Common\Session\Cookie;
use Destiny\Common\Config;
use Destiny\Common\Authentication\AuthenticationService;
use Destiny\Common\Request;
use Destiny\Common\Utils\Http;
use Doctrine\Common\Annotations\AnnotationReader;
ini_set('session.gc_maxlifetime', 5 * 60 * 60);
require __DIR__ . '/../lib/boot.app.php';
$app = Application::instance();
try {
// Routing
$router = new Router();
ControllerAnnotationLoader::factory(
new DirectoryClassIterator (_BASEDIR . '/lib/', 'Destiny/Controllers/'),
new Doctrine\Common\Annotations\CachedReader(new AnnotationReader(), Application::getVerCache()),
$router
);
// Config.links routes
foreach (Config::$a['links'] as $path => $url) {
$router->addRoute(new Route(['path' => $path, 'url' => $url]));
}
$app->setRouter($router);
// Setup user session
$app->setSession(new SessionInstance());
$app->setSessionCookie(new Cookie('sid', Config::$a['cookie']));
$app->setRememberMeCookie(new Cookie('rememberme', Config::$a['cookie']));
$authService = AuthenticationService::instance();
$authService->startSession();
// Attempts to find a route and execute it
$app->executeRequest(new Request([
'uri' => $_SERVER['REQUEST_URI'],
'method' => $_SERVER['REQUEST_METHOD'],
'headers' => Http::extractHeaders($_SERVER),
'address' => Http::extractIpAddress($_SERVER),
'get' => $_GET,
'post' => $_POST
]));
} catch (Exception $e) {
Log::error($e->getMessage());
echo "Application failed to start. Check the error logs for more info.";
}