-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
63 lines (51 loc) · 1.86 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
59
60
61
62
63
<?php
require_once "../config.php";
require_once "../../admin/admin_util.php";
require_once "vendor/autoload.php";
require_once "config.php";
use Pimple\Container;
use CurrikiTsugi\App;
// use Tsugi\Core\LTIX;
use CurrikiTsugi\Interfaces\ControllerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
// $LTI = LTIX::requireData();
$container = new Container();
$container[Request::class] = function($c){
$request = Request::createFromGlobals();
return $request;
};
$container[Response::class] = function($c){
$response = new Response(
null,
Response::HTTP_OK,
['content-type' => 'text/html']
);
return $response;
};
$path_info_parts = [];
$container[ControllerInterface::class] = function($c){
$controller = null;
global $path_info_parts;
if( isset($_SERVER['PATH_INFO']) ) {
$path_info_parts = explode('/', $_SERVER['PATH_INFO'] );
$path_info_parts = array_filter($path_info_parts, function ($el){return !empty(trim($el));});
$path_info_parts = count($path_info_parts) > 0 ? array_values($path_info_parts) : [];
}
if( count($path_info_parts) > 0 ){
$controller_name = "CurrikiTsugi\Controllers\\";
$controller_name_parts = explode('-',$path_info_parts[0]);
$controller_name_parts = array_map(function($item){return ucfirst($item);}, $controller_name_parts);
$controller = $controller_name.implode('',$controller_name_parts);
if (class_exists($controller)) {
global $path_info_parts;
$controller = new $controller($c[Request::class], $c[Response::class]);
}
}
return $controller;
};
$container[App::class] = function($c){
return new App($c[ControllerInterface::class]);
};
$app = $container[App::class];
$app->bootstrap();