-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurls.php
45 lines (38 loc) · 1.25 KB
/
urls.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
<?php
function change_http_method(){
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(isset($_POST['_method'])){
$_SERVER["REQUEST_METHOD"] = strtoupper($_POST['_method']);
}
}
}
change_http_method();
require 'vendor/autoload.php';
$router = new AltoRouter();
include('views.php');
$router->addRoutes(array(
array('GET','/static/.[a:file]?', 'serve_file'),
array('GET','/', 'index'),
array('GET','/tasks', 'list_tasks'),
array('GET','/login', 'get_login'),
array('POST','/login', 'post_login'),
array('GET','/logout', 'logout'),
array('GET','/signup', 'get_signup'),
array('POST','/signup', 'post_signup'),
array('POST','/task/create/', 'create_task'),
array('POST','/login', 'authenticate_login'),
array('PATCH','/task/complete/[i:id]/[a:complete]?/?', 'complete_task'),
));
function serve_file($file){
echo 'kipe';
include('static/'.$file);
}
$match = $router->match();
if( is_array($match) && is_callable( $match['target'] ) ) {
call_user_func_array( $match['target'], $match['params'] );
} else {
// no route was matched
header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
echo isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI']: '/';
echo "\n404";
}