-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
53 lines (47 loc) · 1.6 KB
/
index.php
File metadata and controls
53 lines (47 loc) · 1.6 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
<?php
/**
* koolREST home place
*
* index which processes incoming endpoint calls and json answers
*
* PHP 7.0
*
* Copyright 2017_?
*
* @location /index.php
* @created 2017-04-22
*/
//get main vars used in different files, and core kickoff
require_once('core.php');
require_once('handlers/way.php');
//applying right encoding from this point on
header("Content-Type: application/json; charset=utf-8");
//default return data, which will be json encoded
$returnData = array("error" => "0", "message" => "");
//sanitizing all headers data
$params = sanitize();
//class build handling handling
$className = explode("/", trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), "/"));
if ( count($className) === 2 ) {
$methodName = $className[1];
//all controllers should be inside doers folder
$className = "doers\\" . $className[0];
$do = new $className;
$returnData["error"] = "ER_00050";
$returnData["message"] = "Method does not exist";
//checking if method exists
if (method_exists($className, $methodName)) {
$returnData = $do->{$methodName}($params);
}
//checking as well method _ request method like get, put, delete and so on
$methodName .= "_" . strtolower($_SERVER['REQUEST_METHOD']);
if (method_exists($className, $methodName)) {
$returnData = $do->{$methodName}($params);
}
} else {
//there is not enough args to go on
$returnData["error"] = "ER_00100";
$returnData["message"] = "Invalid method call";
}
//write out rest stuff result
print json_encode($returnData);