|
@@ -8,6 +8,29 @@ class LuRoute {
|
8
|
8
|
*/
|
9
|
9
|
private $middleware = array('Luticate\Utils\ParametersMiddleware');
|
10
|
10
|
|
|
11
|
+ /**
|
|
12
|
+ * @var LuRouteDbo[]
|
|
13
|
+ */
|
|
14
|
+ private $routes = array();
|
|
15
|
+
|
|
16
|
+ /**
|
|
17
|
+ * @var LuRoute
|
|
18
|
+ */
|
|
19
|
+ private static $instance = null;
|
|
20
|
+
|
|
21
|
+ public static function getInstance()
|
|
22
|
+ {
|
|
23
|
+ if (is_null(self::$instance)) {
|
|
24
|
+ self::$instance = new LuRoute();
|
|
25
|
+ }
|
|
26
|
+ return self::$instance;
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ public function getRoutes()
|
|
30
|
+ {
|
|
31
|
+ return $this->routes;
|
|
32
|
+ }
|
|
33
|
+
|
11
|
34
|
/**
|
12
|
35
|
* @param $middleware string
|
13
|
36
|
*/
|
|
@@ -16,7 +39,7 @@ class LuRoute {
|
16
|
39
|
$this->middleware[] = $middleware;
|
17
|
40
|
}
|
18
|
41
|
|
19
|
|
- private function getOptions($url, $business, $method, $permissions, $middleware)
|
|
42
|
+ private function getOptions($method, $url, $business, $method, $permissions, $middleware)
|
20
|
43
|
{
|
21
|
44
|
if (!is_array($permissions)) {
|
22
|
45
|
$permissions = array($permissions);
|
|
@@ -30,14 +53,23 @@ class LuRoute {
|
30
|
53
|
|
31
|
54
|
$middleware_string[] = $mid . (strpos($mid, ":") !== false ? "," : ":") . $permissions_string;
|
32
|
55
|
}
|
33
|
|
- return [function() use($business, $method, $permissions)
|
|
56
|
+
|
|
57
|
+ if (strpos($business, "\\") === false) {
|
|
58
|
+ $business = "App\\Http\\Business\\" . $business . "Business";
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ $route = new LuRouteDbo();
|
|
62
|
+ $route->setUrl($url);
|
|
63
|
+ $route->setBusinessClass($business);
|
|
64
|
+ $route->setMiddlware($middleware_string);
|
|
65
|
+ $route->setPermissions($permissions);
|
|
66
|
+ $route->setMethod($method);
|
|
67
|
+ $this->routes[] = $route;
|
|
68
|
+
|
|
69
|
+ return [function() use($business, $method)
|
34
|
70
|
{
|
35
|
71
|
$controller = new LuController();
|
36
|
72
|
|
37
|
|
- if (strpos($business, "\\") === false) {
|
38
|
|
- $business = "App\\Http\\Business\\" . $business . "Business";
|
39
|
|
- }
|
40
|
|
-
|
41
|
73
|
return $controller->execute($business, $method);
|
42
|
74
|
},
|
43
|
75
|
'middleware' => $middleware_string];
|
|
@@ -54,7 +86,7 @@ class LuRoute {
|
54
|
86
|
public function get($url, $business, $method, $permissions = array(), $middleware = array())
|
55
|
87
|
{
|
56
|
88
|
global $app;
|
57
|
|
- return $app->get($url, $this->getOptions($url, $business, $method, $permissions, $middleware));
|
|
89
|
+ return $app->get($url, $this->getOptions("GET", $url, $business, $method, $permissions, $middleware));
|
58
|
90
|
}
|
59
|
91
|
|
60
|
92
|
/**
|
|
@@ -68,7 +100,7 @@ class LuRoute {
|
68
|
100
|
public function post($url, $business, $method, $permissions = array(), $middleware = array())
|
69
|
101
|
{
|
70
|
102
|
global $app;
|
71
|
|
- return $app->post($url, $this->getOptions($url, $business, $method, $permissions, $middleware));
|
|
103
|
+ return $app->post($url, $this->getOptions("POST", $url, $business, $method, $permissions, $middleware));
|
72
|
104
|
}
|
73
|
105
|
|
74
|
106
|
/**
|
|
@@ -82,7 +114,7 @@ class LuRoute {
|
82
|
114
|
public function put($url, $business, $method, $permissions = array(), $middleware = array())
|
83
|
115
|
{
|
84
|
116
|
global $app;
|
85
|
|
- return $app->put($url, $this->getOptions($url, $business, $method, $permissions, $middleware));
|
|
117
|
+ return $app->put($url, $this->getOptions("PUT", $url, $business, $method, $permissions, $middleware));
|
86
|
118
|
}
|
87
|
119
|
|
88
|
120
|
/**
|
|
@@ -96,6 +128,6 @@ class LuRoute {
|
96
|
128
|
public function delete($url, $business, $method, $permissions = array(), $middleware = array())
|
97
|
129
|
{
|
98
|
130
|
global $app;
|
99
|
|
- return $app->delete($url, $this->getOptions($url, $business, $method, $permissions, $middleware));
|
|
131
|
+ return $app->delete($url, $this->getOptions("DELETE", $url, $business, $method, $permissions, $middleware));
|
100
|
132
|
}
|
101
|
133
|
}
|