-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.php
67 lines (57 loc) · 2.02 KB
/
router.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
<?php
use Config\Routes;
use Config\Config;
class Router
{
public static function getRoute($controller, $method, $params)
{
$config = new Config();
$config = $config->get();
if ($method == "") {
$method = 'index';
}
$routes = Routes::getRoutes();
if (isset($routes[$controller])) {
switch ($config['app_mode']) {
case "api":
if (method_exists('\App\Controllers\Api\Tests\\' . ucfirst($controller), $method) && is_callable(array('\App\Controllers\Api\Tests\\' . ucfirst($controller), $method))) {
try {
call_user_func_array(array('\App\Controllers\Api\Tests\\' . ucfirst($controller), $method), $params);
} catch (ArgumentCountError $e) {
require($config['api_route'] . 'errors/bad_request.php');
BadRequest::ArgumentCountError();
}
} else {
require($config['api_route'] . 'errors/bad_request.php');
BadRequest::index();
}
break;
case "web":
require($config['web_route'] . $routes[$controller]);
if (method_exists('\App\Controllers\Web\\' . ucfirst($controller), $method) && is_callable(array('\App\Controllers\Web\\' . ucfirst($controller), $method))) {
try {
call_user_func_array(array(ucfirst($controller), $method), $params);
} catch (ArgumentCountError $e) {
require($config['web_route'] . 'errors/bad_request.php');
BadRequest::ArgumentCountError();
}
} else {
require($config['web_route'] . 'errors/bad_request.php');
BadRequest::index();
}
break;
}
} else {
switch ($config['app_mode']) {
case "api":
require($config['api_route'] . 'errors/bad_request.php');
BadRequest::index();
break;
case "web":
require($config['web_route'] . 'errors/bad_request.php');
BadRequest::index();
break;
}
}
}
}