/
index.php
executable file
·48 lines (39 loc) · 1.39 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
<?php
namespace Litpi;
require 'includes/classmap.php';
require 'includes/conf.php';
require 'Vendor/autoload.php';
spl_autoload_register('autoloadlitpi');
//INIT REGISTRY VARIABLE - MAIN STORAGE OF APPLICATION
$registry = Registry::getInstance();
$registry->set('conf', $conf);
$db = new MyPdoProxy();
$db->addMaster($conf['db']['host'], $conf['db']['user'], $conf['db']['pass'], $conf['db']['name']);
$db->addSlave($conf['db']['host'], $conf['db']['user'], $conf['db']['pass'], $conf['db']['name']);
$registry->set('db', $db);
/////////////////////////
///// Important, process to include controller file
///This is the main different with LITPI framework core
//Parsing route information to include module/controller
$route = isset($_GET['route']) ? trim($_GET['route'], '/\\') : '';
$parts = explode('/', $route);
for ($i = 0; $i < count($parts); $i++) {
$parts[$i] = htmlspecialchars($parts[$i]);
}
$module = array_shift($parts);
$controller = array_shift($parts);
$registry->set('module', $module);
$registry->set('controller', $controller);
$class = '\\controller\\' . $module . '\\' . $controller;
//Init slim object
$app = new \Slim\Slim();
//check if valid controller
if (classmap($class) != '') {
$myControllerObj = new $class($registry, $app);
$myControllerObj->run();
} else {
$app->notFound(function () use ($app) {
echo file_get_contents('404.html');
});
}
$app->run();