Bladeren bron

clean controller

tags/0.1.0
Robin Thoni 9 jaren geleden
bovenliggende
commit
b8da8c9427
2 gewijzigde bestanden met toevoegingen van 31 en 37 verwijderingen
  1. 0
    17
      src/Utils/LuController.php
  2. 31
    20
      src/Utils/LuRoute.php

+ 0
- 17
src/Utils/LuController.php Bestand weergeven

@@ -6,21 +6,4 @@ use Laravel\Lumen\Routing\Controller as BaseController;
6 6
 
7 7
 class LuController extends BaseController
8 8
 {
9
-    function execute($businessClass, $businessMethod)
10
-    {
11
-        $reflect = new \ReflectionMethod($businessClass, $businessMethod);
12
-        $params = $reflect->getParameters();
13
-
14
-        $args = array();
15
-        foreach ($params as $param) {
16
-            if ($param->isOptional()) {
17
-                $args[$param->getName()] = LuBusiness::getParam($param->getName(), $param->getDefaultValue());
18
-            }
19
-            else {
20
-                $args[$param->getName()] = LuBusiness::checkParam($param->getName());
21
-            }
22
-        }
23
-
24
-        return LuOutputFormatter::formatSuccess(forward_static_call_array(array($businessClass, $businessMethod), $args));
25
-    }
26 9
 }

+ 31
- 20
src/Utils/LuRoute.php Bestand weergeven

@@ -49,7 +49,7 @@ class LuRoute {
49 49
         $this->middleware[] = $middleware;
50 50
     }
51 51
 
52
-    private function getOptions($httpMethod, $url, $business, $method, $permissions, $middleware)
52
+    private function getOptions($httpMethod, $url, $controller, $method, $permissions, $middleware)
53 53
     {
54 54
         if (!is_array($permissions)) {
55 55
             $permissions = array($permissions);
@@ -64,81 +64,92 @@ class LuRoute {
64 64
             $middleware_string[] = $mid . (strpos($mid, ":") !== false ? "," : ":") . $permissions_string;
65 65
         }
66 66
 
67
-        if (strpos($business, "\\") === false) {
68
-            $business = "App\\Http\\Business\\" . $business . "Business";
67
+        if (strpos($controller, "\\") === false) {
68
+            $controller = "App\\Http\\Controller\\" . $controller . "Controller";
69 69
         }
70 70
 
71 71
         $route = new LuRouteDbo();
72 72
         $route->setUrl($url);
73
-        $route->setBusinessClass($business);
73
+        $route->setBusinessClass($controller);
74 74
         $route->setBusinessMethod($method);
75 75
         $route->setMiddlware($middleware_string);
76 76
         $route->setPermissions($permissions);
77 77
         $route->setMethod($httpMethod);
78 78
         $this->routes[] = $route;
79 79
 
80
-        return [function() use($business, $method)
80
+        return [function() use($controller, $method)
81 81
         {
82
-            $controller = new LuController();
83
-
84
-            return $controller->execute($business, $method);
82
+            $reflect = new \ReflectionMethod($controller, $method);
83
+            $params = $reflect->getParameters();
84
+
85
+            $args = array();
86
+            foreach ($params as $param) {
87
+                if ($param->isOptional()) {
88
+                    $args[$param->getName()] = LuBusiness::getParam($param->getName(), $param->getDefaultValue());
89
+                }
90
+                else {
91
+                    $args[$param->getName()] = LuBusiness::checkParam($param->getName());
92
+                }
93
+            }
94
+
95
+            return LuOutputFormatter::formatSuccess(forward_static_call_array(array($controller, $method), $args));
85 96
         },
86 97
             'middleware' => $middleware_string];
87 98
     }
88 99
 
89 100
     /**
90 101
      * @param $url string
91
-     * @param $business string
102
+     * @param $controller string
92 103
      * @param $method string
93 104
      * @param array $permissions string|string[]
94 105
      * @param array $middleware string|string[]
95 106
      * @return mixed
96 107
      */
97
-    public function get($url, $business, $method, $permissions = array(), $middleware = array())
108
+    public function get($url, $controller, $method, $permissions = array(), $middleware = array())
98 109
     {
99 110
         global $app;
100
-        return $app->get($url, $this->getOptions("GET", $url, $business, $method, $permissions, $middleware));
111
+        return $app->get($url, $this->getOptions("GET", $url, $controller, $method, $permissions, $middleware));
101 112
     }
102 113
 
103 114
     /**
104 115
      * @param $url string
105
-     * @param $business string
116
+     * @param $controller string
106 117
      * @param $method string
107 118
      * @param array $permissions string|string[]
108 119
      * @param array $middleware string|string[]
109 120
      * @return mixed
110 121
      */
111
-    public function post($url, $business, $method, $permissions = array(), $middleware = array())
122
+    public function post($url, $controller, $method, $permissions = array(), $middleware = array())
112 123
     {
113 124
         global $app;
114
-        return $app->post($url, $this->getOptions("POST", $url, $business, $method, $permissions, $middleware));
125
+        return $app->post($url, $this->getOptions("POST", $url, $controller, $method, $permissions, $middleware));
115 126
     }
116 127
 
117 128
     /**
118 129
      * @param $url string
119
-     * @param $business string
130
+     * @param $controller string
120 131
      * @param $method string
121 132
      * @param array $permissions string|string[]
122 133
      * @param array $middleware string|string[]
123 134
      * @return mixed
124 135
      */
125
-    public function put($url, $business, $method, $permissions = array(), $middleware = array())
136
+    public function put($url, $controller, $method, $permissions = array(), $middleware = array())
126 137
     {
127 138
         global $app;
128
-        return $app->put($url, $this->getOptions("PUT", $url, $business, $method, $permissions, $middleware));
139
+        return $app->put($url, $this->getOptions("PUT", $url, $controller, $method, $permissions, $middleware));
129 140
     }
130 141
 
131 142
     /**
132 143
      * @param $url string
133
-     * @param $business string
144
+     * @param $controller string
134 145
      * @param $method string
135 146
      * @param array $permissions string|string[]
136 147
      * @param array $middleware string|string[]
137 148
      * @return mixed
138 149
      */
139
-    public function delete($url, $business, $method, $permissions = array(), $middleware = array())
150
+    public function delete($url, $controller, $method, $permissions = array(), $middleware = array())
140 151
     {
141 152
         global $app;
142
-        return $app->delete($url, $this->getOptions("DELETE", $url, $business, $method, $permissions, $middleware));
153
+        return $app->delete($url, $this->getOptions("DELETE", $url, $controller, $method, $permissions, $middleware));
143 154
     }
144 155
 }

Laden…
Annuleren
Opslaan