-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·131 lines (97 loc) · 3.07 KB
/
index.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/*--------------------------------------------
* Lili Framework
* Daniel Mendonça
* (Beta) Version 0.13.26
*
* A very simple Micro-Framework to develop single page systems in Angular, VUE, React, Vanilla etc
* Data content: Returns always in json format
*
* Data Example: ?class=lists&method=fu
---------------------------------------------*/
header('Access-Control-Allow-Origin: *');
header('Content-type:application/json; charset=utf-8');
require_once "config/config.php";
// Main class. Use this class as an extend to your App class
include "core/main.php";
// Error reporting.
// Advice about Error reporting: set ERROR_REPORTING = 0 in production enviroment
if ( ERROR_REPORTING == 0 ) {
error_reporting(0);
} else {
error_reporting(E_ALL);
}
date_default_timezone_set('America/Sao_Paulo');
// Call service classes and build them in one single service class
if ( isset( $_GET['class'] ) && $_GET['class'] != "" && isset( $_GET['method'] ) && $_GET['method'] != "" ) {
//$include = "app/{$_GET['class']}/{$_GET['class']}.php";
$include = "app/{$_GET['class']}/index.php";
if ( file_exists( $include ) ) {
// Call Class file
include $include;
// Instantiate Object
$controller = New $_GET['class']( $config );
} else {
errorReport( "Class" );
}
if ( method_exists( $controller , $_GET['method'] ) ) {
// Saves method reference
$method = $_GET['method'];
// Verifies if there are data parameters to send
unset( $_GET['class'] , $_GET['method'] );
$keys = array_keys( $_GET );
$param = ( count($keys) > 0 )? $_GET: "";
// Call method
$output = $controller->$method($param);
// Output
// Return nothing. No message, no error warning, just a big empty ( return Array("void" => "void") )
if ($output[key($output)] == 'void') {
die();
// Return error if there is no information
} else if ( $output[key($output)] == null ) {
$output = Array(
key($output) => Array(
"error" => Array(
"message" => "no data"
)
)
);
}
// Show result in json format
echo json_encode( objectToArray( $output ) );
} else {
errorReport( "Method" );
}
} else {
// Show result in json format
echo json_encode( objectToArray( Array (
"error" => Array( "message" => "no data" )
) ) );
}
/*--------------------------------------------
*
* Specific functions for this controller
*
---------------------------------------------*/
function objectToArray ($object)
{
switch (gettype($object)) {
case 'object':
return array_map('objectToArray', (array) $object);
break;
case 'array':
return $object;
break;
default:
return array("default" => $object);
break;
}
}
function errorReport ($msg)
{
echo json_encode( array(
"Error" => "{$msg} doesn't exist"
) );
die();
}