This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
100 lines (79 loc) · 2.35 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
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
96
97
98
99
100
<?php
/**
* index.php is meant to setup basic library lookup paths as well as
* load the configuration. After the setup is done the request will
* be handled and forwarded to the respective controller.
*
* Lunr's preferred Controller setup uses URL based controller, method
* and parameter definitions. From the client (browser) side this could
* look like this:
*
* http://www.example.org/controller/method/parameter1/parameter2/....
*
* URL rewriting rules (for apache, lighttpd, etc) should take care of
* transforming the URL to something resembling this pattern:
*
* http://www.example.org/index.php?controller=controller&method=method¶m1=parameter1&....
*
* This makes those values available from PHP over the $_GET super global.
*/
// SECURITY: do not allow html tags as URL parameters
foreach($_GET AS $get=>$val)
{
$_GET[$get] = htmlspecialchars(strip_tags($val));
}
$base = __DIR__;
// Define application config lookup path
set_include_path(
$base . '/config:'
);
// Include framework config
require_once 'conf.lunr.inc.php';
// Add system config paths to lookup path
set_include_path(
get_include_path() . ':' .
$base . '/src' . ':' .
$config['path']['lunr']
);
// Load and setup class file autloader
require_once 'Lunr/Core/Autoloader.php';
$autoloader = new Lunr\Core\Autoloader();
$autoloader->register();
$config = new Lunr\Core\Configuration($config);
$locator = new Lunr\Core\ConfigServiceLocator($config);
$config->load_file('application');
$config->load_file('logging');
$config->load_database_config();
// Set up application error log
ini_set("error_log", $config['log']['application'] . $config['error_log']);
// Request handling
ob_start();
if (PHP_SAPI === 'cli')
{
$request = $locator->clirequest();
}
else
{
$request = $locator->webrequest();
}
$locator->override('request', $request);
$front = $locator->frontcontroller();
$response = $locator->response();
$controller = $front->get_controller('src');
if ($controller === '')
{
$response->set_return_code($request->call, Lunr\Corona\HttpCode::NOT_IMPLEMENTED);
$response->set_error_message($request->call, 'Not implemented!');
}
else
{
$controller = new $controller($locator);
$front->dispatch($controller);
}
if ($response->get_return_code() === 200)
{
$view = $response->view;
$locator->{$view}()->print_page();
}
ob_get_flush();
?>