Completed
Push — master ( e7eed4...46d40e )
by Sinnarasa
02:49
created
src/Routing/Middleware.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
         if (isset($this->router->collection->middleware['global_middleware']))
33 33
             foreach ($this->router->collection->middleware['global_middleware'] as $mid) {
34 34
                 if (class_exists($mid)) {
35
-                    $mid_global = call_user_func($this->router->getConfig()['di'],$mid);
35
+                    $mid_global = call_user_func($this->router->getConfig()['di'], $mid);
36 36
                     if (method_exists($mid_global, 'handle')) $this->callHandler($mid_global);
37 37
                 }
38 38
             }
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
         if (isset($this->router->collection->middleware['block_middleware']))
47 47
             if (isset($this->router->collection->middleware['block_middleware'][$this->router->route->getBlock()]) && class_exists($this->router->collection->middleware['block_middleware'][$this->router->route->getBlock()])) {
48 48
                 $class = $this->router->collection->middleware['block_middleware'][$this->router->route->getBlock()];
49
-                $mid_block = call_user_func($this->router->getConfig()['di'],$class);
49
+                $mid_block = call_user_func($this->router->getConfig()['di'], $class);
50 50
                 if (method_exists($mid_block, 'handle')) $this->callHandler($mid_block);
51 51
             }
52 52
     }
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
             $ctrl = str_replace('\\', '/', $this->router->route->getTarget('controller'));
61 61
             if (isset($this->router->collection->middleware['class_middleware'][$ctrl]) && class_exists($this->router->route->getTarget('controller'))) {
62 62
                 $class = $this->router->collection->middleware['class_middleware'][$ctrl];
63
-                $mid_class = call_user_func($this->router->getConfig()['di'],$class);
63
+                $mid_class = call_user_func($this->router->getConfig()['di'], $class);
64 64
                 if (method_exists($mid_class, 'handle')) $this->callHandler($mid_class);
65 65
             }
66 66
         }
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
         if (isset($this->router->collection->middleware['route_middleware']))
75 75
             if (isset($this->router->route->getPath()['middleware']) && class_exists($this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']])) {
76 76
                 $class = $this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']];
77
-                $mid_route = call_user_func($this->router->getConfig()['di'],$class);
77
+                $mid_route = call_user_func($this->router->getConfig()['di'], $class);
78 78
                 if (method_exists($mid_route, 'handle')) $this->callHandler($mid_route);
79 79
             }
80 80
     }
@@ -83,13 +83,13 @@  discard block
 block discarded – undo
83 83
      * @param $instance
84 84
      * @return mixed
85 85
      */
86
-    private function callHandler($instance){
86
+    private function callHandler($instance) {
87 87
         $reflectionMethod = new ReflectionMethod($instance, 'handle');
88 88
         $dependencies = [];
89 89
         foreach ($reflectionMethod->getParameters() as $arg)
90 90
             if (!is_null($arg->getClass()))
91 91
                 $dependencies[] = $this->getClass($arg->getClass()->name);
92
-        $dependencies = array_merge($dependencies,[$this->router->route]);
92
+        $dependencies = array_merge($dependencies, [$this->router->route]);
93 93
         return $reflectionMethod->invokeArgs($instance, $dependencies);
94 94
     }
95 95
 
@@ -97,8 +97,8 @@  discard block
 block discarded – undo
97 97
      * @param $class
98 98
      * @return Route|RouteCollection|Router|mixed
99 99
      */
100
-    private function getClass($class){
101
-        switch($class){
100
+    private function getClass($class) {
101
+        switch ($class) {
102 102
             case 'JetFire\Routing\Route':
103 103
                 return $this->router->route;
104 104
                 break;
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
                 return $this->router->collection;
110 110
                 break;
111 111
             default:
112
-                return call_user_func_array($this->router->getConfig()['di'],[$class]);
112
+                return call_user_func_array($this->router->getConfig()['di'], [$class]);
113 113
                 break;
114 114
         }
115 115
     }
Please login to merge, or discard this patch.
Braces   +28 added lines, -16 removed lines patch added patch discarded remove patch
@@ -29,11 +29,14 @@  discard block
 block discarded – undo
29 29
      */
30 30
     public function globalMiddleware()
31 31
     {
32
-        if (isset($this->router->collection->middleware['global_middleware']))
33
-            foreach ($this->router->collection->middleware['global_middleware'] as $mid) {
32
+        if (isset($this->router->collection->middleware['global_middleware'])) {
33
+                    foreach ($this->router->collection->middleware['global_middleware'] as $mid) {
34 34
                 if (class_exists($mid)) {
35
-                    $mid_global = call_user_func($this->router->getConfig()['di'],$mid);
36
-                    if (method_exists($mid_global, 'handle')) $this->callHandler($mid_global);
35
+                    $mid_global = call_user_func($this->router->getConfig()['di'],$mid);
36
+        }
37
+                    if (method_exists($mid_global, 'handle')) {
38
+                        $this->callHandler($mid_global);
39
+                    }
37 40
                 }
38 41
             }
39 42
     }
@@ -43,11 +46,14 @@  discard block
 block discarded – undo
43 46
      */
44 47
     public function blockMiddleware()
45 48
     {
46
-        if (isset($this->router->collection->middleware['block_middleware']))
47
-            if (isset($this->router->collection->middleware['block_middleware'][$this->router->route->getBlock()]) && class_exists($this->router->collection->middleware['block_middleware'][$this->router->route->getBlock()])) {
48
-                $class = $this->router->collection->middleware['block_middleware'][$this->router->route->getBlock()];
49
+        if (isset($this->router->collection->middleware['block_middleware'])) {
50
+                    if (isset($this->router->collection->middleware['block_middleware'][$this->router->route->getBlock()]) && class_exists($this->router->collection->middleware['block_middleware'][$this->router->route->getBlock()])) {
51
+                $class = $this->router->collection->middleware['block_middleware'][$this->router->route->getBlock()];
52
+        }
49 53
                 $mid_block = call_user_func($this->router->getConfig()['di'],$class);
50
-                if (method_exists($mid_block, 'handle')) $this->callHandler($mid_block);
54
+                if (method_exists($mid_block, 'handle')) {
55
+                    $this->callHandler($mid_block);
56
+                }
51 57
             }
52 58
     }
53 59
 
@@ -61,7 +67,9 @@  discard block
 block discarded – undo
61 67
             if (isset($this->router->collection->middleware['class_middleware'][$ctrl]) && class_exists($this->router->route->getTarget('controller'))) {
62 68
                 $class = $this->router->collection->middleware['class_middleware'][$ctrl];
63 69
                 $mid_class = call_user_func($this->router->getConfig()['di'],$class);
64
-                if (method_exists($mid_class, 'handle')) $this->callHandler($mid_class);
70
+                if (method_exists($mid_class, 'handle')) {
71
+                    $this->callHandler($mid_class);
72
+                }
65 73
             }
66 74
         }
67 75
     }
@@ -71,11 +79,14 @@  discard block
 block discarded – undo
71 79
      */
72 80
     public function routeMiddleware()
73 81
     {
74
-        if (isset($this->router->collection->middleware['route_middleware']))
75
-            if (isset($this->router->route->getPath()['middleware']) && class_exists($this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']])) {
76
-                $class = $this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']];
82
+        if (isset($this->router->collection->middleware['route_middleware'])) {
83
+                    if (isset($this->router->route->getPath()['middleware']) && class_exists($this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']])) {
84
+                $class = $this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']];
85
+        }
77 86
                 $mid_route = call_user_func($this->router->getConfig()['di'],$class);
78
-                if (method_exists($mid_route, 'handle')) $this->callHandler($mid_route);
87
+                if (method_exists($mid_route, 'handle')) {
88
+                    $this->callHandler($mid_route);
89
+                }
79 90
             }
80 91
     }
81 92
 
@@ -86,9 +97,10 @@  discard block
 block discarded – undo
86 97
     private function callHandler($instance){
87 98
         $reflectionMethod = new ReflectionMethod($instance, 'handle');
88 99
         $dependencies = [];
89
-        foreach ($reflectionMethod->getParameters() as $arg)
90
-            if (!is_null($arg->getClass()))
91
-                $dependencies[] = $this->getClass($arg->getClass()->name);
100
+        foreach ($reflectionMethod->getParameters() as $arg) {
101
+                    if (!is_null($arg->getClass()))
102
+                $dependencies[] = $this->getClass($arg->getClass()->name);
103
+        }
92 104
         $dependencies = array_merge($dependencies,[$this->router->route]);
93 105
         return $reflectionMethod->invokeArgs($instance, $dependencies);
94 106
     }
Please login to merge, or discard this patch.