-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.php
42 lines (33 loc) · 1.04 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
<?php // Plankton
$root = __DIR__.'/app';
$app = include($root.'/app.php');
function asset($path) {
$directory = dirname($_SERVER['SCRIPT_NAME']);
if ($directory[strlen($directory)-1] == '/') {
$directory = substr($directory, 0, -1);
}
return $directory.$path;
}
function path($url = '') {
return $_SERVER['SCRIPT_NAME'].'/'.$url;
}
function render($page, array $variables = array(), $layout = 'layout') {
global $app, $root;
extract($variables, EXTR_SKIP);
include($root.'/views/'.($layout ? $layout : $page).'.php');
}
$page = empty($_SERVER['PATH_INFO']) ? '/' : $_SERVER['PATH_INFO'];
$actions = array();
foreach ($app['controllers'] as $controller) {
$file = $root.'/controllers/'.$controller.'.php';
$actions = array_merge($actions, include($file));
}
$app['action'] = isset($actions[$page]) ? $page : '/error';
$action = $actions[$app['action']];
if ($response = $action($app)) {
if (is_array($response)) {
render($response[0], $response);
} else {
echo $response;
}
}