-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.php
More file actions
55 lines (48 loc) · 1.66 KB
/
controller.php
File metadata and controls
55 lines (48 loc) · 1.66 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
<?php
header('Access-Control-Allow-Origin: *');
header( "Content-Type: application/json; charset=utf-8" );
// Turn off error reporting
ini_set("display_startup_errors",false);
ini_set("display_errors",false);
ini_set("html_errors",false);
ini_set("docref_root",false);
ini_set("docref_ext",false);
// Set default values
define( "ROOTDIR", __dir__ );
define( "APPDIR", ROOTDIR . "/application" );
define("REQUEST_URI",strtolower($_SERVER["REQUEST_URI"]));
header($_SERVER["SERVER_PROTOCOL"]." 503 Service Unavailable");
$json = (object) null;
$json->status->code = 503;
$json->status->message = "Service Unavailable";
// Display JSON on exit.
function display($json) {
echo json_encode($json);
}
register_shutdown_function('display',$json);
/*
// Echo back request
if($_SERVER["REQUEST_METHOD"]!=="GET") {
header($_SERVER["SERVER_PROTOCOL"]." 200 OK");
$json->url = $_SERVER["REQUEST_URI"];
$REQUEST = json_decode(file_get_contents('php://input'));
$json->{strtolower($_SERVER["REQUEST_METHOD"])} = $REQUEST;
exit;
}
*/
// Check request format
if(!in_array($_SERVER["REQUEST_METHOD"], array("GET","POST","PUT","OPTIONS"))) {
header($_SERVER["SERVER_PROTOCOL"]." 405 Method Not Allowed");
$json->status->code = 405;
$json->status->message = "Method Not Allowed";
exit;
}
// Process URI
if(strpos(REQUEST_URI,"?")===false)
$params = explode("/", REQUEST_URI);
else if(strpos(substr(REQUEST_URI,-2),"?")!==false) //fix for rare edge case when an url ends with a question mark
$params = explode("/", REQUEST_URI);
else
$params = explode("/", substr(REQUEST_URI,0,strpos(REQUEST_URI,"?")));
$params = array_values(array_filter($params));
include APPDIR . "/router.php";