Completed
Push — master ( 2aa3b5...86f1fc )
by Sinnarasa
04:02
created
src/Routing/Middleware.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
                 if (is_array($blocks)) {
47 47
                     foreach ($blocks as $block)
48 48
                         if (class_exists($block))
49
-                            if($this->callHandler($block) === false) return false;
49
+                            if ($this->callHandler($block) === false) return false;
50 50
                 }
51 51
                 elseif (is_string($blocks) && class_exists($blocks))
52 52
                     return $this->callHandler($blocks);
@@ -63,10 +63,10 @@  discard block
 block discarded – undo
63 63
             $ctrl = str_replace('\\', '/', $this->router->route->getTarget('controller'));
64 64
             if (isset($this->router->collection->middleware['class_middleware'][$ctrl]) && class_exists($this->router->route->getTarget('controller'))) {
65 65
                 $classes = $this->router->collection->middleware['class_middleware'][$ctrl];
66
-                if(is_array($classes)){
66
+                if (is_array($classes)) {
67 67
                     foreach ($classes as $class)
68
-                        if($this->callHandler($class) === false)return false;
69
-                }elseif(is_string($classes))
68
+                        if ($this->callHandler($class) === false)return false;
69
+                }elseif (is_string($classes))
70 70
                     return $this->callHandler($classes);
71 71
             }
72 72
         }
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
         if (isset($this->router->collection->middleware['route_middleware']))
82 82
             if (isset($this->router->route->getPath()['middleware']) && class_exists($this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']])) {
83 83
                 $classes = $this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']];
84
-                if(is_array($classes)){
84
+                if (is_array($classes)) {
85 85
                     foreach ($classes as $class)
86
-                        if($this->callHandler($class) === false)return false;
87
-                }elseif(is_string($classes))
86
+                        if ($this->callHandler($class) === false)return false;
87
+                }elseif (is_string($classes))
88 88
                     return $this->callHandler($classes);
89 89
             }
90 90
         return null;
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
      * @param $class
95 95
      * @return mixed
96 96
      */
97
-    private function callHandler($class){
98
-        $instance = call_user_func($this->router->getConfig()['di'],$class);
97
+    private function callHandler($class) {
98
+        $instance = call_user_func($this->router->getConfig()['di'], $class);
99 99
         if (method_exists($instance, 'handle')) {
100 100
             $reflectionMethod = new ReflectionMethod($instance, 'handle');
101 101
             $dependencies = [];
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
      * @param $class
113 113
      * @return Route|RouteCollection|Router|mixed
114 114
      */
115
-    private function getClass($class){
116
-        switch($class){
115
+    private function getClass($class) {
116
+        switch ($class) {
117 117
             case 'JetFire\Routing\Route':
118 118
                 return $this->router->route;
119 119
             case 'JetFire\Routing\Router':
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
             case 'JetFire\Routing\RouteCollection':
122 122
                 return $this->router->collection;
123 123
             default:
124
-                return call_user_func_array($this->router->getConfig()['di'],[$class]);
124
+                return call_user_func_array($this->router->getConfig()['di'], [$class]);
125 125
         }
126 126
     }
127 127
 }
Please login to merge, or discard this patch.
Braces   +35 added lines, -26 removed lines patch added patch discarded remove patch
@@ -29,9 +29,10 @@  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 $class)
34
-                if (class_exists($class)) return $this->callHandler($class);
32
+        if (isset($this->router->collection->middleware['global_middleware'])) {
33
+                    foreach ($this->router->collection->middleware['global_middleware'] as $class)
34
+                if (class_exists($class)) return $this->callHandler($class);
35
+        }
35 36
         return null;
36 37
     }
37 38
 
@@ -40,16 +41,18 @@  discard block
 block discarded – undo
40 41
      */
41 42
     public function blockMiddleware()
42 43
     {
43
-        if (isset($this->router->collection->middleware['block_middleware']))
44
-            if (isset($this->router->collection->middleware['block_middleware'][$this->router->route->getTarget('block')])) {
45
-                $blocks = $this->router->collection->middleware['block_middleware'][$this->router->route->getTarget('block')];
44
+        if (isset($this->router->collection->middleware['block_middleware'])) {
45
+                    if (isset($this->router->collection->middleware['block_middleware'][$this->router->route->getTarget('block')])) {
46
+                $blocks = $this->router->collection->middleware['block_middleware'][$this->router->route->getTarget('block')];
47
+        }
46 48
                 if (is_array($blocks)) {
47
-                    foreach ($blocks as $block)
48
-                        if (class_exists($block))
49
-                            if($this->callHandler($block) === false) return false;
50
-                }
51
-                elseif (is_string($blocks) && class_exists($blocks))
52
-                    return $this->callHandler($blocks);
49
+                    foreach ($blocks as $block) {
50
+                                            if (class_exists($block))
51
+                            if($this->callHandler($block) === false) return false;
52
+                    }
53
+                } elseif (is_string($blocks) && class_exists($blocks)) {
54
+                                    return $this->callHandler($blocks);
55
+                }
53 56
             }
54 57
         return null;
55 58
     }
@@ -64,10 +67,12 @@  discard block
 block discarded – undo
64 67
             if (isset($this->router->collection->middleware['class_middleware'][$ctrl]) && class_exists($this->router->route->getTarget('controller'))) {
65 68
                 $classes = $this->router->collection->middleware['class_middleware'][$ctrl];
66 69
                 if(is_array($classes)){
67
-                    foreach ($classes as $class)
68
-                        if($this->callHandler($class) === false)return false;
69
-                }elseif(is_string($classes))
70
-                    return $this->callHandler($classes);
70
+                    foreach ($classes as $class) {
71
+                                            if($this->callHandler($class) === false)return false;
72
+                    }
73
+                } elseif(is_string($classes)) {
74
+                                    return $this->callHandler($classes);
75
+                }
71 76
             }
72 77
         }
73 78
         return null;
@@ -78,14 +83,17 @@  discard block
 block discarded – undo
78 83
      */
79 84
     public function routeMiddleware()
80 85
     {
81
-        if (isset($this->router->collection->middleware['route_middleware']))
82
-            if (isset($this->router->route->getPath()['middleware']) && class_exists($this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']])) {
83
-                $classes = $this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']];
86
+        if (isset($this->router->collection->middleware['route_middleware'])) {
87
+                    if (isset($this->router->route->getPath()['middleware']) && class_exists($this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']])) {
88
+                $classes = $this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']];
89
+        }
84 90
                 if(is_array($classes)){
85
-                    foreach ($classes as $class)
86
-                        if($this->callHandler($class) === false)return false;
87
-                }elseif(is_string($classes))
88
-                    return $this->callHandler($classes);
91
+                    foreach ($classes as $class) {
92
+                                            if($this->callHandler($class) === false)return false;
93
+                    }
94
+                } elseif(is_string($classes)) {
95
+                                    return $this->callHandler($classes);
96
+                }
89 97
             }
90 98
         return null;
91 99
     }
@@ -99,9 +107,10 @@  discard block
 block discarded – undo
99 107
         if (method_exists($instance, 'handle')) {
100 108
             $reflectionMethod = new ReflectionMethod($instance, 'handle');
101 109
             $dependencies = [];
102
-            foreach ($reflectionMethod->getParameters() as $arg)
103
-                if (!is_null($arg->getClass()))
104
-                    $dependencies[] = $this->getClass($arg->getClass()->name);
110
+            foreach ($reflectionMethod->getParameters() as $arg) {
111
+                            if (!is_null($arg->getClass()))
112
+                    $dependencies[] = $this->getClass($arg->getClass()->name);
113
+            }
105 114
             $dependencies = array_merge($dependencies, [$this->router->route]);
106 115
             return $reflectionMethod->invokeArgs($instance, $dependencies);
107 116
         }
Please login to merge, or discard this patch.
src/Routing/Router.php 1 patch
Braces   +25 added lines, -12 removed lines patch added patch discarded remove patch
@@ -81,8 +81,9 @@  discard block
 block discarded – undo
81 81
      * @param object|array $matcher
82 82
      */
83 83
     public function setMatcher($matcher){
84
-        if(is_object($matcher))
85
-            $matcher = [$matcher];
84
+        if(is_object($matcher)) {
85
+                    $matcher = [$matcher];
86
+        }
86 87
         $this->matcher = $matcher;
87 88
     }
88 89
 
@@ -99,8 +100,12 @@  discard block
 block discarded – undo
99 100
     public function run()
100 101
     {
101 102
         $this->setUrl();
102
-        if ($this->config['generateRoutesPath']) $this->collection->generateRoutesPath();
103
-        if ($this->match()) $this->callTarget();
103
+        if ($this->config['generateRoutesPath']) {
104
+            $this->collection->generateRoutesPath();
105
+        }
106
+        if ($this->match()) {
107
+            $this->callTarget();
108
+        }
104 109
         $this->callResponse();
105 110
     }
106 111
 
@@ -109,8 +114,9 @@  discard block
 block discarded – undo
109 114
      */
110 115
     public function setUrl($url = null)
111 116
     {
112
-        if (is_null($url))
113
-            $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1);
117
+        if (is_null($url)) {
118
+                    $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1);
119
+        }
114 120
         $this->route->setUrl('/' . trim(explode('?', $url)[0], '/'));
115 121
     }
116 122
 
@@ -120,7 +126,9 @@  discard block
 block discarded – undo
120 126
     public function match()
121 127
     {
122 128
         foreach ($this->matcher as $key => $matcher) {
123
-            if (call_user_func([$this->matcher[$key], 'match'])) return true;
129
+            if (call_user_func([$this->matcher[$key], 'match'])) {
130
+                return true;
131
+            }
124 132
         }
125 133
         return false;
126 134
     }
@@ -155,11 +163,16 @@  discard block
 block discarded – undo
155 163
         if (isset($this->route->getDetail()['response_templates']) && isset($this->route->getDetail()['response_templates'][$code = $this->response->getStatusCode()])) {
156 164
             $this->route->setCallback($this->route->getDetail()['response_templates'][$code]);
157 165
             $matcher = null;
158
-            foreach($this->matcher as $instance) if($instance instanceof ArrayMatcher) $matcher = $instance;
159
-            if(is_null($matcher))$matcher = new ArrayMatcher($this);
160
-            foreach (call_user_func([$matcher, 'getResolver']) as $match)
161
-                if (is_array($target = call_user_func_array([$matcher, $match], [$this->route->getCallback()]))){
162
-                    call_user_func_array([$matcher, 'setTarget'],[$target]);
166
+            foreach($this->matcher as $instance) {
167
+                if($instance instanceof ArrayMatcher) $matcher = $instance;
168
+            }
169
+            if(is_null($matcher)) {
170
+                $matcher = new ArrayMatcher($this);
171
+            }
172
+            foreach (call_user_func([$matcher, 'getResolver']) as $match) {
173
+                            if (is_array($target = call_user_func_array([$matcher, $match], [$this->route->getCallback()]))){
174
+                    call_user_func_array([$matcher, 'setTarget'],[$target]);
175
+            }
163 176
                     $this->callTarget();
164 177
                     break;
165 178
                 }
Please login to merge, or discard this patch.