-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
56 lines (48 loc) · 1.27 KB
/
index.php
File metadata and controls
56 lines (48 loc) · 1.27 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
<?php
// Autoload toro handlers
function __autoload($class) {
if(strpos($class, '\\') !== false) {
$class = substr($class, strrpos($class, '\\') + 1);
}
$classFile = "handlers/{$class}.php";
if(strstr($class, 'Handler') && file_exists($classFile)) {
require_once $classFile;
}
}
require_once 'library/core.php';
require_once 'library/toro.php';
require_once 'config/config.php';
/**
* Push put and delete request variables into $_POST.
*/
ToroHook::add('before_request', function() {
$input = json_decode(file_get_contents('php://input'), true);
switch(strtolower($_SERVER['REQUEST_METHOD'])) {
case 'get':
case 'post': break;
case 'put': $_POST = $input; break;
case 'delete': $_POST = $input; break;
default: throw new Exception('Invalid request type'); break;
}
});
/**
* Close the database connection.
*/
ToroHook::add('after_request', function() {
Zurv\Registry::getInstance()->db = null;
});
/**
* Set routes.
*/
$site = new ToroApplication(array(
array('/', 'AppHandler'),
array('/recipe/([1-9][0-9]*)', 'RecipeHandler'),
array('/recipes', 'RecipesHandler'),
array('/recipes/count', 'RecipesCountHandler'),
array('/ingredients', 'IngredientsHandler'),
array('/manage', 'ManageHandler')
));
/**
* Have fun with your application!
*/
$site->serve();