-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
159 lines (75 loc) · 2.35 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
use AppWeb\ApiController;
/**
* Entry point for html/api Controller
*/
return new class() {
/**
* int
* override display_errors setting
* for example: (int) 0 will WSOD, (int) 1 will display php errors
*
* ignored unless value is 0 or 1
*/
const DISPLAY_ERRORS = 1;
/**
* int
* override error_reprting level
* ignored unless value is integer
*/
const ERROR_REPORTING = E_ALL & ~E_DEPRECATED;
/**
* string
* change this to the path of the SpyDash 'app' directory
*/
const APP_DIR = __DIR__ . '/../app';
/**
* string
* 'name' of route to correspond to to routing autoload configuration;
* for example, when the name is "my_route" a file in the location
* {APP_DIR}/config/routing/my_route.php would need to exist.
*/
const ROUTE_NAME = 'api';
/**
* string
* the request method used when it cannot be determined from $_SERVER['REQUEST_METHOD']
*/
const FALLBACK_REQUEST_METHOD = 'GET';
/**
* @uses self::DISPLAY_ERRORS
* @uses self::ERROR_REPORTING
* @uses self::APP_DIR
* @uses self::ROUTE_NAME
*/
public function __construct() {
if (
(self::DISPLAY_ERRORS === 0) ||
(self::DISPLAY_ERRORS === 1)
) {
ini_set('display_errors',self::DISPLAY_ERRORS);
}
if (
is_int(self::ERROR_REPORTING)
) {
error_reporting(self::ERROR_REPORTING);
}
require realpath(self::APP_DIR).'/autoload.php';
$routeNamespace = require realpath(self::APP_DIR) . '/config/routing/'.self::ROUTE_NAME .'.php';
if (!empty($_SERVER ['PATH_INFO'] )) {
$resource = $_SERVER ['PATH_INFO'];
} else {
$resource = '/';
}
if (!empty($_SERVER["CONTENT_TYPE"])) {
$contentType = $_SERVER["CONTENT_TYPE"];
} else {
$contentType = '';
}
if (!empty($_SERVER['REQUEST_METHOD'])) {
$requestMethod = $_SERVER['REQUEST_METHOD'];
} else {
$requestMethod = self::FALLBACK_REQUEST_METHOD;
}
new ApiController($resource,self::APP_DIR, $routeNamespace, $requestMethod, $contentType);
}
};