-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
67 lines (48 loc) · 2.22 KB
/
index.php
File metadata and controls
67 lines (48 loc) · 2.22 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
<?php
require_once 'vendor/autoload.php';
require_once 'Configuration.php';
use App\Core\DbConfiguration;
use App\Core\DbConnection;
use App\Core\Router;
ob_start();
$databaseConfiguration = new DbConfiguration(
Configuration::DB_HOST,
Configuration::DB_USER,
Configuration::DB_PASS,
Configuration::DB_NAME
);
$databaseConnection = new DbConnection($databaseConfiguration);
$url = strval(filter_input(INPUT_GET, 'URL'));
$httpMethod = filter_input(INPUT_SERVER, 'REQUEST_METHOD');
$router = new Router();
$routes = require_once 'Routes.php';
foreach($routes as $route){
$router->add($route);
}
$route = $router->find($httpMethod, $url);
$arguments = $route->extractArguments($url);
$fullControllerName = '\\App\\Controllers\\' . $route->getControllerName() . 'Controller';
$controller = new $fullControllerName($databaseConnection);
$fingerprintProviderFactoryClass = Configuration::FINGERPRINT_PROVIDER_FACTORY;
$fingerprintProviderFactoryMethod = Configuration::FINGERPRINT_PROVIDER_METHOD;
$fingerprintProviderFactoryArgs = Configuration::FINGERPRINT_PROVIDER_ARGS;
$fingerprintProviderFactory = new $fingerprintProviderFactoryClass;
$fingerprintProvider = $fingerprintProviderFactory->$fingerprintProviderFactoryMethod(...$fingerprintProviderFactoryArgs); // ove tri tacke znace da raspakujemo ove argumente.
$sessionStorageClassName = Configuration::SESSION_STORAGE;
$sessionStorageConstructorArguments = Configuration::SESSION_STORAGE_DATA;
$sessionStorage = new $sessionStorageClassName(...$sessionStorageConstructorArguments);
$session = new App\Core\Session\Session($sessionStorage, Configuration::SESSION_LIFETIME);
$session->setFingerPrintProvider($fingerprintProvider);
$controller->setSession($session);
$controller->getSession()->reload();
$controller->__pre();
call_user_func_array([$controller, $route->getMethodName()], $arguments);
$controller->getSession()->save();
$data = $controller->getData();
$loader = new Twig_Loader_Filesystem("./Views");
$twig = new Twig_Environment($loader, [
"cache" => "./twig-cache",
"auto_reload" => true
]);
$data['BASE'] = Configuration::BASE;
echo $twig->render($route->getControllerName() . '/' . $route->getMethodName() . '.html', $data);