-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.php
46 lines (38 loc) · 954 Bytes
/
api.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
<?php
require 'vendor/autoload.php';
use TTNUlm\API;
use TTNUlm\Flood;
$router = new AltoRouter();
$api = new API();
$router->map('GET', '/', function() use ($api) {
echo 'root';
});
//**********
// Distance
//**********
$router->map('GET', '/distance/[i:id]/?', function($id) use ($api) {
$from = $_GET['from'];
$to = $_GET['to'];
$api->returnDistance($id, $from, $to);
});
//**********
// State
//**********
$router->map('GET', '/state/[i:id]/?', function($id) use ($api) {
$api->returnState($id);
});
//**********
// Sensors
//**********
$router->map('GET', '/sensors/?', function() use ($api) {
$api->returnSensors();
});
// get matches
$match = $router->match();
// call closure or throw 404 status
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');
}