-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassRouter.php
More file actions
78 lines (61 loc) · 1.74 KB
/
ClassRouter.php
File metadata and controls
78 lines (61 loc) · 1.74 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
use Idae\Api\IdaeApiQuery;
use Idae\Api\IdaeApiRest;
/**
* Created by PhpStorm.
* User: Mydde
* Date: 10/08/2017
* Time: 20:43
*/
class Router extends AltoRouter {
function __construct() {
parent::__construct();
$this->do_match();
}
function do_match() {
$this->addRoutes($this->routes());
//
$match = $this->match();
if ($match) {
// var_dump($match);
// var_dump(json_decode(file_get_contents('php://input'), JSON_OBJECT_AS_ARRAY | JSON_PRETTY_PRINT));
// echo json_decode(file_get_contents('php://input'),JSON_OBJECT_AS_ARRAY | JSON_PRETTY_PRINT);
if (is_string($match['target']) && strpos($match['target'], '#') !== false) {
$is_cl = explode('#', $match['target']);
if (sizeof($is_cl) == 2) {
$cl = new $is_cl[0]();
$meth = $is_cl[1];
$cl->$meth($match['params']);
}
} else if (is_callable($match['target'])) {
// var_dump($match);
call_user_func_array($match['target'], $match['params']);
} else {
// no route was matched
echo "404";
// header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}
}
}
public function routes() {
return [
['POST', '/api/idql/[*:scheme]', function (string $scheme) {
$_POST = json_decode(file_get_contents('php://input'), JSON_OBJECT_AS_ARRAY | JSON_PRETTY_PRINT);
$defaulIdql = [
'method' => 'find',
'scheme' => $scheme,
'limit' => 10,
'page' => 0,
];
$idql = array_merge($defaulIdql,$_POST );
//IdaeApiQuery::idql($idql);
$api = new IdaeApiRest();
$api->doIdql($idql);
}],
['GET|POST|PATCH|PUT', '/api/[*:uri_vars]', function ($uri_vars) {
$api = new IdaeApiRest();
$api->doRest();
}],
];
}
}