Completed
Push — master ( b0d6bc...c2c9db )
by Sinnarasa
05:21
created
src/Routing/Response.php 2 patches
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -166,8 +166,9 @@
 block discarded – undo
166 166
      */
167 167
     public function sendHeaders()
168 168
     {
169
-        foreach($this->headers as $key => $content)
170
-            header($key.' : '.$content);
169
+        foreach($this->headers as $key => $content) {
170
+                    header($key.' : '.$content);
171
+        }
171 172
         http_response_code($this->getStatusCode());
172 173
         return $this;
173 174
     }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * Class Response
8 8
  * @package JetFire\Routing
9 9
  */
10
-class Response implements ResponseInterface{
10
+class Response implements ResponseInterface {
11 11
 
12 12
     /**
13 13
      * @var array
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     public static $statusTexts = array(
54 54
         100 => 'Continue',
55 55
         101 => 'Switching Protocols',
56
-        102 => 'Processing',            // RFC2518
56
+        102 => 'Processing', // RFC2518
57 57
         200 => 'OK',
58 58
         201 => 'Created',
59 59
         202 => 'Accepted',
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
         204 => 'No Content',
62 62
         205 => 'Reset Content',
63 63
         206 => 'Partial Content',
64
-        207 => 'Multi-Status',          // RFC4918
65
-        208 => 'Already Reported',      // RFC5842
66
-        226 => 'IM Used',               // RFC3229
64
+        207 => 'Multi-Status', // RFC4918
65
+        208 => 'Already Reported', // RFC5842
66
+        226 => 'IM Used', // RFC3229
67 67
         300 => 'Multiple Choices',
68 68
         301 => 'Moved Permanently',
69 69
         302 => 'Found',
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
         304 => 'Not Modified',
72 72
         305 => 'Use Proxy',
73 73
         307 => 'Temporary Redirect',
74
-        308 => 'Permanent Redirect',    // RFC7238
74
+        308 => 'Permanent Redirect', // RFC7238
75 75
         400 => 'Bad Request',
76 76
         401 => 'Unauthorized',
77 77
         402 => 'Payment Required',
@@ -90,26 +90,26 @@  discard block
 block discarded – undo
90 90
         415 => 'Unsupported Media Type',
91 91
         416 => 'Range Not Satisfiable',
92 92
         417 => 'Expectation Failed',
93
-        418 => 'I\'m a teapot',                                               // RFC2324
94
-        422 => 'Unprocessable Entity',                                        // RFC4918
95
-        423 => 'Locked',                                                      // RFC4918
96
-        424 => 'Failed Dependency',                                           // RFC4918
97
-        425 => 'Reserved for WebDAV advanced collections expired proposal',   // RFC2817
98
-        426 => 'Upgrade Required',                                            // RFC2817
99
-        428 => 'Precondition Required',                                       // RFC6585
100
-        429 => 'Too Many Requests',                                           // RFC6585
101
-        431 => 'Request Header Fields Too Large',                             // RFC6585
93
+        418 => 'I\'m a teapot', // RFC2324
94
+        422 => 'Unprocessable Entity', // RFC4918
95
+        423 => 'Locked', // RFC4918
96
+        424 => 'Failed Dependency', // RFC4918
97
+        425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817
98
+        426 => 'Upgrade Required', // RFC2817
99
+        428 => 'Precondition Required', // RFC6585
100
+        429 => 'Too Many Requests', // RFC6585
101
+        431 => 'Request Header Fields Too Large', // RFC6585
102 102
         500 => 'Internal Server Error',
103 103
         501 => 'Not Implemented',
104 104
         502 => 'Bad Gateway',
105 105
         503 => 'Service Unavailable',
106 106
         504 => 'Gateway Timeout',
107 107
         505 => 'HTTP Version Not Supported',
108
-        506 => 'Variant Also Negotiates (Experimental)',                      // RFC2295
109
-        507 => 'Insufficient Storage',                                        // RFC4918
110
-        508 => 'Loop Detected',                                               // RFC5842
111
-        510 => 'Not Extended',                                                // RFC2774
112
-        511 => 'Network Authentication Required',                             // RFC6585
108
+        506 => 'Variant Also Negotiates (Experimental)', // RFC2295
109
+        507 => 'Insufficient Storage', // RFC4918
110
+        508 => 'Loop Detected', // RFC5842
111
+        510 => 'Not Extended', // RFC2774
112
+        511 => 'Network Authentication Required', // RFC6585
113 113
     );
114 114
 
115 115
     /**
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      */
167 167
     public function sendHeaders()
168 168
     {
169
-        foreach($this->headers as $key => $content)
169
+        foreach ($this->headers as $key => $content)
170 170
             header($key.' : '.$content);
171 171
         http_response_code($this->getStatusCode());
172 172
         return $this;
Please login to merge, or discard this patch.
src/Routing/Route.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public function setDetail($detail)
129 129
     {
130
-        $this->detail = array_merge($detail,$this->detail);
130
+        $this->detail = array_merge($detail, $this->detail);
131 131
     }
132 132
 
133 133
     /**
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
     /**
174 174
      * @return array
175 175
      */
176
-    public function getData(){
177
-        return (isset($this->getDetail()['data']) && is_array($this->getDetail()['data']))?$this->getDetail()['data']:[];
176
+    public function getData() {
177
+        return (isset($this->getDetail()['data']) && is_array($this->getDetail()['data'])) ? $this->getDetail()['data'] : [];
178 178
     }
179 179
 
180 180
     /**
Please login to merge, or discard this patch.
Braces   +18 added lines, -8 removed lines patch added patch discarded remove patch
@@ -52,10 +52,18 @@  discard block
 block discarded – undo
52 52
      */
53 53
     public function set($args = [])
54 54
     {
55
-        if (isset($args['name'])) $this->name = $args['name'];
56
-        if (isset($args['callback'])) $this->callback = $args['callback'];
57
-        if (isset($args['target'])) $this->target = $args['target'];
58
-        if (isset($args['detail'])) $this->detail = $args['detail'];
55
+        if (isset($args['name'])) {
56
+            $this->name = $args['name'];
57
+        }
58
+        if (isset($args['callback'])) {
59
+            $this->callback = $args['callback'];
60
+        }
61
+        if (isset($args['target'])) {
62
+            $this->target = $args['target'];
63
+        }
64
+        if (isset($args['detail'])) {
65
+            $this->detail = $args['detail'];
66
+        }
59 67
     }
60 68
 
61 69
     /**
@@ -145,8 +153,9 @@  discard block
 block discarded – undo
145 153
      */
146 154
     public function getTarget($key = null)
147 155
     {
148
-        if (!is_null($key))
149
-            return isset($this->target[$key]) ? $this->target[$key] : '';
156
+        if (!is_null($key)) {
157
+                    return isset($this->target[$key]) ? $this->target[$key] : '';
158
+        }
150 159
         return empty($this->target) ? '' : $this->target;
151 160
     }
152 161
 
@@ -165,8 +174,9 @@  discard block
 block discarded – undo
165 174
      */
166 175
     public function hasTarget($key = null)
167 176
     {
168
-        if (!is_null($key))
169
-            return isset($this->target[$key]) ? true : false;
177
+        if (!is_null($key)) {
178
+                    return isset($this->target[$key]) ? true : false;
179
+        }
170 180
         return empty($this->target) ? false : true;
171 181
     }
172 182
 
Please login to merge, or discard this patch.
src/Routing/Matcher/ArrayMatcher.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
     }
159 159
 
160 160
     /**
161
-     * @param $regex
161
+     * @param string $regex
162 162
      * @return bool
163 163
      */
164 164
     private function routeMatch($regex)
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
     }
177 177
 
178 178
     /**
179
-     * @return bool
179
+     * @return null|boolean
180 180
      */
181 181
     private function generateTarget()
182 182
     {
Please login to merge, or discard this patch.
Braces   +46 added lines, -26 removed lines patch added patch discarded remove patch
@@ -102,7 +102,9 @@  discard block
 block discarded – undo
102 102
                     $this->request['route'] = preg_replace_callback('#:([\w]+)#', [$this, 'paramMatch'], '/' . trim(trim($this->request['prefix'], '/') . '/' . trim($route, '/'), '/'));
103 103
                     if ($this->routeMatch('#^' . $this->request['route'] . '$#')) {
104 104
                         $this->setCallback();
105
-                        if(!is_null($response = $this->generateTarget())) return $response;
105
+                        if(!is_null($response = $this->generateTarget())) {
106
+                            return $response;
107
+                        }
106 108
                     }
107 109
                 }
108 110
             }
@@ -118,10 +120,12 @@  discard block
 block discarded – undo
118 120
         $url = (isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : 'http') . '://' . ($host = (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST']));
119 121
         $host = explode(':',$host)[0];
120 122
         $domain = $this->router->collection->getDomain($url);
121
-        if(!empty($this->request['subdomain']) && $route[0] == '/') $route = trim($this->request['subdomain'],'.').'.'.$domain.$route;
123
+        if(!empty($this->request['subdomain']) && $route[0] == '/') {
124
+            $route = trim($this->request['subdomain'],'.').'.'.$domain.$route;
125
+        }
122 126
         if($route[0] == '/'){
123 127
             return ($host != $domain) ? false : true;
124
-        }elseif($route[0] != '/' && $host != $domain){
128
+        } elseif($route[0] != '/' && $host != $domain){
125 129
             $route = substr($route, 0, strpos($route, "/"));
126 130
             $route = str_replace('{host}', $domain, $route);
127 131
             $route = preg_replace_callback('#{subdomain}#', [$this, 'subdomainMatch'], $route);
@@ -166,8 +170,9 @@  discard block
 block discarded – undo
166 170
     {
167 171
         if (substr($this->request['route'], -1) == '*') {
168 172
             $pos = strpos($this->request['route'], '*');
169
-            if (substr($this->router->route->getUrl(), 0, $pos) == substr($this->request['route'], 0, $pos) && isset($this->request['params']))
170
-                return true;
173
+            if (substr($this->router->route->getUrl(), 0, $pos) == substr($this->request['route'], 0, $pos) && isset($this->request['params'])) {
174
+                            return true;
175
+            }
171 176
         }
172 177
         if (preg_match($regex, $this->router->route->getUrl(), $this->request['parameters'])) {
173 178
             array_shift($this->request['parameters']);
@@ -185,8 +190,9 @@  discard block
 block discarded – undo
185 190
             foreach ($this->resolver as $resolver) {
186 191
                 if (is_array($target = call_user_func_array([$this, $resolver], [$this->router->route->getCallback()]))) {
187 192
                     $this->setTarget($target);
188
-                    if ($this->router->middleware->globalMiddleware() === false || $this->router->middleware->blockMiddleware() === false || $this->router->middleware->classMiddleware() === false || $this->router->middleware->routeMiddleware() === false)
189
-                        return null;
193
+                    if ($this->router->middleware->globalMiddleware() === false || $this->router->middleware->blockMiddleware() === false || $this->router->middleware->classMiddleware() === false || $this->router->middleware->routeMiddleware() === false) {
194
+                                            return null;
195
+                    }
190 196
                     $this->router->response->setStatusCode(202);
191 197
                     return true;
192 198
                 }
@@ -213,14 +219,18 @@  discard block
 block discarded – undo
213 219
      */
214 220
     private function setCallback(){
215 221
         if (isset($this->request['params'])) {
216
-            if(is_callable($this->request['params']))
217
-                $this->router->route->setCallback($this->request['params']);
218
-            else {
222
+            if(is_callable($this->request['params'])) {
223
+                            $this->router->route->setCallback($this->request['params']);
224
+            } else {
219 225
                 (is_array($this->request['params']) && isset($this->request['params']['use']))
220 226
                     ? $this->router->route->setCallback($this->request['params']['use'])
221 227
                     : $this->router->route->setCallback($this->request['params']);
222
-                if (isset($this->request['params']['name'])) $this->router->route->setName($this->request['params']['name']);
223
-                if (isset($this->request['params']['method'])) $this->request['params']['method'] = is_array($this->request['params']['method']) ? $this->request['params']['method'] : [$this->request['params']['method']];
228
+                if (isset($this->request['params']['name'])) {
229
+                    $this->router->route->setName($this->request['params']['name']);
230
+                }
231
+                if (isset($this->request['params']['method'])) {
232
+                    $this->request['params']['method'] = is_array($this->request['params']['method']) ? $this->request['params']['method'] : [$this->request['params']['method']];
233
+                }
224 234
             }
225 235
         }
226 236
     }
@@ -230,9 +240,12 @@  discard block
 block discarded – undo
230 240
      */
231 241
     public function validMethod()
232 242
     {
233
-        if(is_callable($this->request['params']))return true;
234
-        if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
235
-            return (isset($this->request['params']['ajax']) && $this->request['params']['ajax'] === true) ? true : false;
243
+        if(is_callable($this->request['params'])) {
244
+            return true;
245
+        }
246
+        if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
247
+                    return (isset($this->request['params']['ajax']) && $this->request['params']['ajax'] === true) ? true : false;
248
+        }
236 249
         $method = (isset($this->request['params']['method'])) ? $this->request['params']['method'] : ['GET'];
237 250
         return (in_array($this->router->route->getMethod(), $method)) ? true : false;
238 251
     }
@@ -296,20 +309,25 @@  discard block
 block discarded – undo
296 309
     {
297 310
         if (is_string($callback) && strpos($callback, '@') !== false) {
298 311
             $routes = explode('@', $callback);
299
-            if (!isset($routes[1])) $routes[1] = 'index';
312
+            if (!isset($routes[1])) {
313
+                $routes[1] = 'index';
314
+            }
300 315
             if ($routes[1] == '{method}'){
301 316
                 $this->request['parameters'] = explode('/',str_replace(str_replace('*','',$this->request['route']),'',$this->router->route->getUrl()));
302 317
                 $routes[1] = $this->request['parameters'][0];
303 318
                 array_shift($this->request['parameters']);
304
-                if(preg_match('/[A-Z]/', $routes[1])) return false;
319
+                if(preg_match('/[A-Z]/', $routes[1])) {
320
+                    return false;
321
+                }
305 322
                 $routes[1] = lcfirst(str_replace(' ','',ucwords(str_replace('-',' ',$routes[1]))));
306 323
             }
307 324
             $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0;
308 325
             $class = (class_exists($routes[0]))
309 326
                 ? $routes[0]
310 327
                 : $this->router->collection->getRoutes()['ctrl_namespace_' . $index] . $routes[0];
311
-            if (!class_exists($class))
312
-                throw new \Exception('Class "' . $class . '." is not found');
328
+            if (!class_exists($class)) {
329
+                            throw new \Exception('Class "' . $class . '." is not found');
330
+            }
313 331
             if (method_exists($class, $routes[1])) {
314 332
                 return [
315 333
                     'dispatcher' => $this->dispatcher['isController'],
@@ -318,8 +336,9 @@  discard block
 block discarded – undo
318 336
                     'action' => $routes[1]
319 337
                 ];
320 338
             }
321
-            if (!strpos($callback, '{method}') !== false)
322
-                throw new \Exception('The required method "' . $routes[1] . '" is not found in "' . $class . '"');
339
+            if (!strpos($callback, '{method}') !== false) {
340
+                            throw new \Exception('The required method "' . $routes[1] . '" is not found in "' . $class . '"');
341
+            }
323 342
         }
324 343
         return false;
325 344
     }
@@ -337,9 +356,9 @@  discard block
 block discarded – undo
337 356
             $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0;
338 357
             $viewDir = $this->router->collection->getRoutes('view_dir_' . $index);
339 358
             $target = null;
340
-            if (in_array('.' . $extension, $this->router->getConfig()['templateExtension']) && (is_file($fullPath = $viewDir . $path) || is_file($fullPath = $path)))
341
-                $target = $fullPath;
342
-            else {
359
+            if (in_array('.' . $extension, $this->router->getConfig()['templateExtension']) && (is_file($fullPath = $viewDir . $path) || is_file($fullPath = $path))) {
360
+                            $target = $fullPath;
361
+            } else {
343 362
                 foreach ($this->router->getConfig()['templateExtension'] as $ext) {
344 363
                     if (is_file($fullPath = $viewDir . $path . $ext) || is_file($fullPath = $path . $ext)) {
345 364
                         $target = $fullPath;
@@ -348,8 +367,9 @@  discard block
 block discarded – undo
348 367
                     }
349 368
                 }
350 369
             }
351
-            if(is_null($target))
352
-                throw new \Exception('Template file "' . $path . '" is not found in "' . $viewDir . '"');
370
+            if(is_null($target)) {
371
+                            throw new \Exception('Template file "' . $path . '" is not found in "' . $viewDir . '"');
372
+            }
353 373
             return [
354 374
                 'dispatcher' => $this->dispatcher['isTemplate'],
355 375
                 'template'   => $target,
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
     /**
26 26
      * @var array
27 27
      */
28
-    private $resolver = ['isClosureAndTemplate','isControllerAndTemplate','isTemplate'];
28
+    private $resolver = ['isClosureAndTemplate', 'isControllerAndTemplate', 'isTemplate'];
29 29
 
30 30
     /**
31 31
      * @var array
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
         'isClosure' => 'JetFire\Routing\Dispatcher\ClosureDispatcher',
35 35
         'isController' => 'JetFire\Routing\Dispatcher\ControllerDispatcher',
36 36
         'isTemplate' => 'JetFire\Routing\Dispatcher\TemplateDispatcher',
37
-        'isControllerAndTemplate' => ['JetFire\Routing\Dispatcher\ControllerDispatcher','JetFire\Routing\Dispatcher\TemplateDispatcher'],
38
-        'isClosureAndTemplate' => ['JetFire\Routing\Dispatcher\ClosureDispatcher','JetFire\Routing\Dispatcher\TemplateDispatcher'],
37
+        'isControllerAndTemplate' => ['JetFire\Routing\Dispatcher\ControllerDispatcher', 'JetFire\Routing\Dispatcher\TemplateDispatcher'],
38
+        'isClosureAndTemplate' => ['JetFire\Routing\Dispatcher\ClosureDispatcher', 'JetFire\Routing\Dispatcher\TemplateDispatcher'],
39 39
     ];
40 40
 
41 41
     /**
@@ -49,14 +49,14 @@  discard block
 block discarded – undo
49 49
     /**
50 50
      * @param array $resolver
51 51
      */
52
-    public function setResolver($resolver = []){
52
+    public function setResolver($resolver = []) {
53 53
         $this->resolver = $resolver;
54 54
     }
55 55
 
56 56
     /**
57 57
      * @param string $resolver
58 58
      */
59
-    public function addResolver($resolver){
59
+    public function addResolver($resolver) {
60 60
         $this->resolver[] = $resolver;
61 61
     }
62 62
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
     /**
72 72
      * @param array $dispatcher
73 73
      */
74
-    public function setDispatcher($dispatcher = []){
74
+    public function setDispatcher($dispatcher = []) {
75 75
         $this->dispatcher = $dispatcher;
76 76
     }
77 77
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      * @param $class
81 81
      * @internal param array $dispatcher
82 82
      */
83
-    public function addDispatcher($method,$class){
83
+    public function addDispatcher($method, $class) {
84 84
         $this->dispatcher[$method] = $class;
85 85
     }
86 86
 
@@ -91,17 +91,17 @@  discard block
 block discarded – undo
91 91
     {
92 92
         $this->request = [];
93 93
         for ($i = 0; $i < $this->router->collection->countRoutes; ++$i) {
94
-            $this->request['prefix'] = ($this->router->collection->getRoutes('prefix_' . $i) != '') ? $this->router->collection->getRoutes('prefix_' . $i) : '';
95
-            $this->request['subdomain'] = ($this->router->collection->getRoutes('subdomain_' . $i) != '') ? $this->router->collection->getRoutes('subdomain_' . $i) : '';
96
-            foreach ($this->router->collection->getRoutes('routes_' . $i) as $route => $params) {
94
+            $this->request['prefix'] = ($this->router->collection->getRoutes('prefix_'.$i) != '') ? $this->router->collection->getRoutes('prefix_'.$i) : '';
95
+            $this->request['subdomain'] = ($this->router->collection->getRoutes('subdomain_'.$i) != '') ? $this->router->collection->getRoutes('subdomain_'.$i) : '';
96
+            foreach ($this->router->collection->getRoutes('routes_'.$i) as $route => $params) {
97 97
                 $this->request['params'] = $params;
98 98
                 $this->request['collection_index'] = $i;
99
-                if($this->checkSubdomain($route)) {
99
+                if ($this->checkSubdomain($route)) {
100 100
                     $route = strstr($route, '/');
101
-                    $this->request['route'] = preg_replace_callback('#:([\w]+)#', [$this, 'paramMatch'], '/' . trim(trim($this->request['prefix'], '/') . '/' . trim($route, '/'), '/'));
102
-                    if ($this->routeMatch('#^' . $this->request['route'] . '$#')) {
101
+                    $this->request['route'] = preg_replace_callback('#:([\w]+)#', [$this, 'paramMatch'], '/'.trim(trim($this->request['prefix'], '/').'/'.trim($route, '/'), '/'));
102
+                    if ($this->routeMatch('#^'.$this->request['route'].'$#')) {
103 103
                         $this->setCallback();
104
-                        if(!is_null($response = $this->generateTarget())) return $response;
104
+                        if (!is_null($response = $this->generateTarget())) return $response;
105 105
                     }
106 106
                 }
107 107
             }
@@ -113,20 +113,20 @@  discard block
 block discarded – undo
113 113
      * @param $route
114 114
      * @return bool
115 115
      */
116
-    private function checkSubdomain($route){
117
-        $url = (isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : 'http') . '://' . ($host = (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST']));
118
-        $host = explode(':',$host)[0];
116
+    private function checkSubdomain($route) {
117
+        $url = (isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : 'http').'://'.($host = (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST']));
118
+        $host = explode(':', $host)[0];
119 119
         $domain = $this->router->collection->getDomain($url);
120
-        if(!empty($this->request['subdomain']) && $route[0] == '/') $route = trim($this->request['subdomain'],'.').'.'.$domain.$route;
121
-        if($route[0] == '/'){
120
+        if (!empty($this->request['subdomain']) && $route[0] == '/') $route = trim($this->request['subdomain'], '.').'.'.$domain.$route;
121
+        if ($route[0] == '/') {
122 122
             return ($host != $domain) ? false : true;
123
-        }elseif($route[0] != '/' && $host != $domain){
123
+        }elseif ($route[0] != '/' && $host != $domain) {
124 124
             $route = substr($route, 0, strpos($route, "/"));
125 125
             $route = str_replace('{host}', $domain, $route);
126 126
             $route = preg_replace_callback('#{subdomain}#', [$this, 'subdomainMatch'], $route);
127
-            if (preg_match('#^' . $route . '$#', $host, $this->request['called_subdomain'])) {
127
+            if (preg_match('#^'.$route.'$#', $host, $this->request['called_subdomain'])) {
128 128
                 $this->request['called_subdomain'] = array_shift($this->request['called_subdomain']);
129
-                $this->request['subdomain'] = str_replace('.'.$domain,'',$host);
129
+                $this->request['subdomain'] = str_replace('.'.$domain, '', $host);
130 130
                 return true;
131 131
             }
132 132
         }
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
     private function subdomainMatch()
140 140
     {
141 141
         if (is_array($this->request['params']) && isset($this->request['params']['subdomain'])) {
142
-            return '(' . $this->request['params']['subdomain'] . ')';
142
+            return '('.$this->request['params']['subdomain'].')';
143 143
         }
144 144
         return '([^/]+)';
145 145
     }
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
     {
153 153
         if (is_array($this->request['params']) && isset($this->request['params']['arguments'][$match[1]])) {
154 154
             $this->request['params']['arguments'][$match[1]] = str_replace('(', '(?:', $this->request['params']['arguments'][$match[1]]);
155
-            return '(' . $this->request['params']['arguments'][$match[1]] . ')';
155
+            return '('.$this->request['params']['arguments'][$match[1]].')';
156 156
         }
157 157
         return '([^/]+)';
158 158
     }
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
      */
181 181
     private function generateTarget()
182 182
     {
183
-        if($this->validMethod()) {
183
+        if ($this->validMethod()) {
184 184
             foreach ($this->resolver as $resolver) {
185 185
                 if (is_array($target = call_user_func_array([$this, $resolver], [$this->router->route->getCallback()]))) {
186 186
                     $this->setTarget($target);
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
     /**
200 200
      * @param array $target
201 201
      */
202
-    public function setTarget($target = []){
202
+    public function setTarget($target = []) {
203 203
         $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0;
204 204
         $this->router->route->setDetail($this->request);
205 205
         $this->router->route->setTarget($target);
@@ -210,9 +210,9 @@  discard block
 block discarded – undo
210 210
     /**
211 211
      *
212 212
      */
213
-    private function setCallback(){
213
+    private function setCallback() {
214 214
         if (isset($this->request['params'])) {
215
-            if(is_callable($this->request['params']))
215
+            if (is_callable($this->request['params']))
216 216
                 $this->router->route->setCallback($this->request['params']);
217 217
             else {
218 218
                 (is_array($this->request['params']) && isset($this->request['params']['use']))
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
      */
230 230
     public function validMethod()
231 231
     {
232
-        if(is_callable($this->request['params']))return true;
232
+        if (is_callable($this->request['params']))return true;
233 233
         if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
234 234
             return (isset($this->request['params']['ajax']) && $this->request['params']['ajax'] === true) ? true : false;
235 235
         $method = (isset($this->request['params']['method'])) ? $this->request['params']['method'] : ['GET'];
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
      * @return array|bool
242 242
      * @throws \Exception
243 243
      */
244
-    public function isClosureAndTemplate($callback){
245
-        if(is_array($cls = $this->isClosure($callback))) {
244
+    public function isClosureAndTemplate($callback) {
245
+        if (is_array($cls = $this->isClosure($callback))) {
246 246
             if (is_array($this->request['params']) && isset($this->request['params']['template']) && is_array($tpl = $this->isTemplate($this->request['params']['template']))) {
247
-                return array_merge(array_merge($cls, $tpl),[
247
+                return array_merge(array_merge($cls, $tpl), [
248 248
                     'dispatcher' => $this->dispatcher['isClosureAndTemplate']
249 249
                 ]);
250 250
             }
@@ -258,10 +258,10 @@  discard block
 block discarded – undo
258 258
      * @return array|bool
259 259
      * @throws \Exception
260 260
      */
261
-    public function isControllerAndTemplate($callback){
262
-        if(is_array($ctrl = $this->isController($callback))) {
261
+    public function isControllerAndTemplate($callback) {
262
+        if (is_array($ctrl = $this->isController($callback))) {
263 263
             if (is_array($this->request['params']) && isset($this->request['params']['template']) && is_array($tpl = $this->isTemplate($this->request['params']['template']))) {
264
-                return array_merge(array_merge($ctrl, $tpl),[
264
+                return array_merge(array_merge($ctrl, $tpl), [
265 265
                     'dispatcher' => $this->dispatcher['isControllerAndTemplate']
266 266
                 ]);
267 267
             }
@@ -296,19 +296,19 @@  discard block
 block discarded – undo
296 296
         if (is_string($callback) && strpos($callback, '@') !== false) {
297 297
             $routes = explode('@', $callback);
298 298
             if (!isset($routes[1])) $routes[1] = 'index';
299
-            if ($routes[1] == '{method}'){
300
-                $this->request['parameters'] = explode('/',str_replace(str_replace('*','',$this->request['route']),'',$this->router->route->getUrl()));
299
+            if ($routes[1] == '{method}') {
300
+                $this->request['parameters'] = explode('/', str_replace(str_replace('*', '', $this->request['route']), '', $this->router->route->getUrl()));
301 301
                 $routes[1] = $this->request['parameters'][0];
302 302
                 array_shift($this->request['parameters']);
303
-                if(preg_match('/[A-Z]/', $routes[1])) return false;
304
-                $routes[1] = lcfirst(str_replace(' ','',ucwords(str_replace('-',' ',$routes[1]))));
303
+                if (preg_match('/[A-Z]/', $routes[1])) return false;
304
+                $routes[1] = lcfirst(str_replace(' ', '', ucwords(str_replace('-', ' ', $routes[1]))));
305 305
             }
306 306
             $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0;
307 307
             $class = (class_exists($routes[0]))
308 308
                 ? $routes[0]
309
-                : $this->router->collection->getRoutes()['ctrl_namespace_' . $index] . $routes[0];
309
+                : $this->router->collection->getRoutes()['ctrl_namespace_'.$index].$routes[0];
310 310
             if (!class_exists($class))
311
-                throw new \Exception('Class "' . $class . '." is not found');
311
+                throw new \Exception('Class "'.$class.'." is not found');
312 312
             if (method_exists($class, $routes[1])) {
313 313
                 return [
314 314
                     'dispatcher' => $this->dispatcher['isController'],
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
                 ];
319 319
             }
320 320
             if (!strpos($callback, '{method}') !== false)
321
-                throw new \Exception('The required method "' . $routes[1] . '" is not found in "' . $class . '"');
321
+                throw new \Exception('The required method "'.$routes[1].'" is not found in "'.$class.'"');
322 322
         }
323 323
         return false;
324 324
     }
@@ -330,25 +330,25 @@  discard block
 block discarded – undo
330 330
      */
331 331
     public function isTemplate($callback)
332 332
     {
333
-        if(is_string($callback) && strpos($callback, '@') === false) {
333
+        if (is_string($callback) && strpos($callback, '@') === false) {
334 334
             $path = trim($callback, '/');
335 335
             $extension = substr(strrchr($path, "."), 1);
336 336
             $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0;
337
-            $viewDir = $this->router->collection->getRoutes('view_dir_' . $index);
337
+            $viewDir = $this->router->collection->getRoutes('view_dir_'.$index);
338 338
             $target = null;
339
-            if (in_array('.' . $extension, $this->router->getConfig()['templateExtension']) && (is_file($fullPath = $viewDir . $path) || is_file($fullPath = $path)))
339
+            if (in_array('.'.$extension, $this->router->getConfig()['templateExtension']) && (is_file($fullPath = $viewDir.$path) || is_file($fullPath = $path)))
340 340
                 $target = $fullPath;
341 341
             else {
342 342
                 foreach ($this->router->getConfig()['templateExtension'] as $ext) {
343
-                    if (is_file($fullPath = $viewDir . $path . $ext) || is_file($fullPath = $path . $ext)) {
343
+                    if (is_file($fullPath = $viewDir.$path.$ext) || is_file($fullPath = $path.$ext)) {
344 344
                         $target = $fullPath;
345 345
                         $extension = substr(strrchr($ext, "."), 1);
346 346
                         break;
347 347
                     }
348 348
                 }
349 349
             }
350
-            if(is_null($target))
351
-                throw new \Exception('Template file "' . $path . '" is not found in "' . $viewDir . '"');
350
+            if (is_null($target))
351
+                throw new \Exception('Template file "'.$path.'" is not found in "'.$viewDir.'"');
352 352
             return [
353 353
                 'dispatcher' => $this->dispatcher['isTemplate'],
354 354
                 'template'   => $target,
Please login to merge, or discard this patch.
src/Routing/Matcher/UriMatcher.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@
 block discarded – undo
83 83
     }
84 84
 
85 85
     /**
86
-     * @return bool
86
+     * @return null|boolean
87 87
      */
88 88
     public function match()
89 89
     {
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,8 +90,9 @@
 block discarded – undo
90 90
         foreach($this->resolver as $resolver){
91 91
             if(is_array($target = call_user_func([$this,$resolver]))) {
92 92
                 $this->setTarget($target);
93
-                if($this->router->middleware->globalMiddleware() === false || $this->router->middleware->blockMiddleware() === false || $this->router->middleware->classMiddleware() === false || $this->router->middleware->routeMiddleware() === false)
94
-                    return null;
93
+                if($this->router->middleware->globalMiddleware() === false || $this->router->middleware->blockMiddleware() === false || $this->router->middleware->classMiddleware() === false || $this->router->middleware->routeMiddleware() === false) {
94
+                                    return null;
95
+                }
95 96
                 $this->router->response->setStatusCode(202);
96 97
                 return true;
97 98
             }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
     private $dispatcher = [
33 33
         'isTemplate' => 'JetFire\Routing\Dispatcher\TemplateDispatcher',
34 34
         'isController' => 'JetFire\Routing\Dispatcher\ControllerDispatcher',
35
-        'isControllerAndTemplate' => ['JetFire\Routing\Dispatcher\ControllerDispatcher','JetFire\Routing\Dispatcher\TemplateDispatcher'],
35
+        'isControllerAndTemplate' => ['JetFire\Routing\Dispatcher\ControllerDispatcher', 'JetFire\Routing\Dispatcher\TemplateDispatcher'],
36 36
     ];
37 37
 
38 38
     /**
@@ -46,14 +46,14 @@  discard block
 block discarded – undo
46 46
     /**
47 47
      * @param array $resolver
48 48
      */
49
-    public function setResolver($resolver = []){
49
+    public function setResolver($resolver = []) {
50 50
         $this->resolver = $resolver;
51 51
     }
52 52
 
53 53
     /**
54 54
      * @param string $resolver
55 55
      */
56
-    public function addResolver($resolver){
56
+    public function addResolver($resolver) {
57 57
         $this->resolver[] = $resolver;
58 58
     }
59 59
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      * @param $method
78 78
      * @param $class
79 79
      */
80
-    public function addDispatcher($method,$class){
80
+    public function addDispatcher($method, $class) {
81 81
         $this->dispatcher[$method] = $class;
82 82
     }
83 83
 
@@ -86,10 +86,10 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public function match()
88 88
     {
89
-        foreach($this->resolver as $resolver){
90
-            if(is_array($target = call_user_func([$this,$resolver]))) {
89
+        foreach ($this->resolver as $resolver) {
90
+            if (is_array($target = call_user_func([$this, $resolver]))) {
91 91
                 $this->setTarget($target);
92
-                if($this->router->middleware->globalMiddleware() === false || $this->router->middleware->blockMiddleware() === false || $this->router->middleware->classMiddleware() === false || $this->router->middleware->routeMiddleware() === false)
92
+                if ($this->router->middleware->globalMiddleware() === false || $this->router->middleware->blockMiddleware() === false || $this->router->middleware->classMiddleware() === false || $this->router->middleware->routeMiddleware() === false)
93 93
                     return null;
94 94
                 $this->router->response->setStatusCode(202);
95 95
                 return true;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     /**
102 102
      * @param array $target
103 103
      */
104
-    public function setTarget($target = []){
104
+    public function setTarget($target = []) {
105 105
         $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0;
106 106
         $this->router->route->setDetail($this->request);
107 107
         $this->router->route->setTarget($target);
@@ -112,10 +112,10 @@  discard block
 block discarded – undo
112 112
     /**
113 113
      * @return array|bool
114 114
      */
115
-    public function isControllerAndTemplate(){
116
-        if(is_array($ctrl = $this->isController())) {
115
+    public function isControllerAndTemplate() {
116
+        if (is_array($ctrl = $this->isController())) {
117 117
             if (is_array($tpl = $this->isTemplate())) {
118
-                return array_merge(array_merge($ctrl, $tpl),[
118
+                return array_merge(array_merge($ctrl, $tpl), [
119 119
                     'dispatcher' => $this->dispatcher['isControllerAndTemplate']
120 120
                 ]);
121 121
             }
@@ -131,10 +131,10 @@  discard block
 block discarded – undo
131 131
     {
132 132
         foreach ($this->router->getConfig()['templateExtension'] as $extension) {
133 133
             for ($i = 0; $i < $this->router->collection->countRoutes; ++$i) {
134
-                $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_' . $i), '',$this->router->route->getUrl()));
134
+                $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_'.$i), '', $this->router->route->getUrl()));
135 135
                 $end = array_pop($url);
136 136
                 $url = implode('/', array_map('ucwords', $url)).'/'.$end;
137
-                if (is_file(($template = rtrim($this->router->collection->getRoutes('view_dir_' . $i), '/') . $url . $extension))) {
137
+                if (is_file(($template = rtrim($this->router->collection->getRoutes('view_dir_'.$i), '/').$url.$extension))) {
138 138
                     $this->request['collection_index'] = $i;
139 139
                     return [
140 140
                         'dispatcher' => $this->dispatcher['isTemplate'],
@@ -155,13 +155,13 @@  discard block
 block discarded – undo
155 155
     {
156 156
         $routes = array_slice(explode('/', $this->router->route->getUrl()), 1);
157 157
         $i = 0;
158
-        do{
159
-            $route =  ('/' . $routes[0] == $this->router->collection->getRoutes('prefix_' . $i)) ? array_slice($routes, 1) : $routes;
158
+        do {
159
+            $route = ('/'.$routes[0] == $this->router->collection->getRoutes('prefix_'.$i)) ? array_slice($routes, 1) : $routes;
160 160
             if (isset($route[0])) {
161
-                $class =  (class_exists($this->router->collection->getRoutes('ctrl_namespace_' . $i). ucfirst($route[0]) . 'Controller'))
162
-                    ? $this->router->collection->getRoutes('ctrl_namespace_' . $i). ucfirst($route[0]) . 'Controller'
163
-                    : ucfirst($route[0]) . 'Controller';
164
-                $route[1] = isset($route[1])?$route[1]:'index';
161
+                $class = (class_exists($this->router->collection->getRoutes('ctrl_namespace_'.$i).ucfirst($route[0]).'Controller'))
162
+                    ? $this->router->collection->getRoutes('ctrl_namespace_'.$i).ucfirst($route[0]).'Controller'
163
+                    : ucfirst($route[0]).'Controller';
164
+                $route[1] = isset($route[1]) ? $route[1] : 'index';
165 165
                 if (method_exists($class, $route[1])) {
166 166
                     $this->request['parameters'] = array_slice($route, 2);
167 167
                     $this->request['collection_index'] = $i;
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
                 }
175 175
             }
176 176
             ++$i;
177
-        }while($i < $this->router->collection->countRoutes);
177
+        }while ($i < $this->router->collection->countRoutes);
178 178
         return false;
179 179
     }
180 180
 
Please login to merge, or discard this patch.
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 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
         $this->response->setStatusCode(404);
58 58
         $this->route = is_null($route) ? new Route() : $route;
59 59
         $this->middleware = new Middleware($this);
60
-        $this->config['di'] = function ($class) {
60
+        $this->config['di'] = function($class) {
61 61
             return new $class;
62 62
         };
63 63
     }
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
     {
115 115
         if (is_null($url))
116 116
             $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1);
117
-        $this->route->setUrl('/' . trim(explode('?', $url)[0], '/'));
117
+        $this->route->setUrl('/'.trim(explode('?', $url)[0], '/'));
118 118
     }
119 119
 
120 120
     /**
Please login to merge, or discard this patch.
Braces   +25 added lines, -12 removed lines patch added patch discarded remove patch
@@ -83,8 +83,9 @@  discard block
 block discarded – undo
83 83
      */
84 84
     public function setMatcher($matcher)
85 85
     {
86
-        if (is_object($matcher))
87
-            $matcher = [$matcher];
86
+        if (is_object($matcher)) {
87
+                    $matcher = [$matcher];
88
+        }
88 89
         $this->matcher = $matcher;
89 90
     }
90 91
 
@@ -102,8 +103,12 @@  discard block
 block discarded – undo
102 103
     public function run()
103 104
     {
104 105
         $this->setUrl();
105
-        if ($this->config['generateRoutesPath']) $this->collection->generateRoutesPath();
106
-        if ($this->match()) $this->callTarget();
106
+        if ($this->config['generateRoutesPath']) {
107
+            $this->collection->generateRoutesPath();
108
+        }
109
+        if ($this->match()) {
110
+            $this->callTarget();
111
+        }
107 112
         $this->callResponse();
108 113
     }
109 114
 
@@ -112,8 +117,9 @@  discard block
 block discarded – undo
112 117
      */
113 118
     public function setUrl($url = null)
114 119
     {
115
-        if (is_null($url))
116
-            $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1);
120
+        if (is_null($url)) {
121
+                    $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1);
122
+        }
117 123
         $this->route->setUrl('/' . trim(explode('?', $url)[0], '/'));
118 124
     }
119 125
 
@@ -123,7 +129,9 @@  discard block
 block discarded – undo
123 129
     public function match()
124 130
     {
125 131
         foreach ($this->matcher as $key => $matcher) {
126
-            if (call_user_func([$this->matcher[$key], 'match'])) return true;
132
+            if (call_user_func([$this->matcher[$key], 'match'])) {
133
+                return true;
134
+            }
127 135
         }
128 136
         return false;
129 137
     }
@@ -158,11 +166,16 @@  discard block
 block discarded – undo
158 166
         if (isset($this->route->getDetail()['response_templates']) && isset($this->route->getDetail()['response_templates'][$code = $this->response->getStatusCode()])) {
159 167
             $this->route->setCallback($this->route->getDetail()['response_templates'][$code]);
160 168
             $matcher = null;
161
-            foreach ($this->matcher as $instance) if ($instance instanceof ArrayMatcher) $matcher = $instance;
162
-            if (is_null($matcher)) $matcher = new ArrayMatcher($this);
163
-            foreach (call_user_func([$matcher, 'getResolver']) as $match)
164
-                if (is_array($target = call_user_func_array([$matcher, $match], [$this->route->getCallback()]))) {
165
-                    call_user_func_array([$matcher, 'setTarget'], [$target]);
169
+            foreach ($this->matcher as $instance) {
170
+                if ($instance instanceof ArrayMatcher) $matcher = $instance;
171
+            }
172
+            if (is_null($matcher)) {
173
+                $matcher = new ArrayMatcher($this);
174
+            }
175
+            foreach (call_user_func([$matcher, 'getResolver']) as $match) {
176
+                            if (is_array($target = call_user_func_array([$matcher, $match], [$this->route->getCallback()]))) {
177
+                    call_user_func_array([$matcher, 'setTarget'], [$target]);
178
+            }
166 179
                     $this->callTarget();
167 180
                     break;
168 181
                 }
Please login to merge, or discard this patch.
src/Routing/Dispatcher/TemplateDispatcher.php 1 patch
Braces   +12 added lines, -7 removed lines patch added patch discarded remove patch
@@ -47,14 +47,19 @@
 block discarded – undo
47 47
      */
48 48
     public function call()
49 49
     {
50
-        if ($this->response->getStatusCode() == 202)
51
-            $this->setContentType($this->route->getTarget('extension'));
52
-        if (isset($this->route->getTarget('callback')[$this->route->getTarget('extension')]))
53
-            $this->response->setContent(call_user_func_array($this->route->getTarget('callback')[$this->route->getTarget('extension')], [$this->route]));
54
-        else {
50
+        if ($this->response->getStatusCode() == 202) {
51
+                    $this->setContentType($this->route->getTarget('extension'));
52
+        }
53
+        if (isset($this->route->getTarget('callback')[$this->route->getTarget('extension')])) {
54
+                    $this->response->setContent(call_user_func_array($this->route->getTarget('callback')[$this->route->getTarget('extension')], [$this->route]));
55
+        } else {
55 56
             ob_start();
56
-            if (isset($this->route->getTarget()['data'])) extract($this->route->getTarget('data'));
57
-            if (isset($this->route->getParams()['data'])) extract($this->route->getParams()['data']);
57
+            if (isset($this->route->getTarget()['data'])) {
58
+                extract($this->route->getTarget('data'));
59
+            }
60
+            if (isset($this->route->getParams()['data'])) {
61
+                extract($this->route->getParams()['data']);
62
+            }
58 63
             require($this->route->getTarget('template'));
59 64
             $this->response->setContent(ob_get_clean());
60 65
         }
Please login to merge, or discard this patch.
src/Routing/Dispatcher/ClosureDispatcher.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,8 +43,11 @@
 block discarded – undo
43 43
             $this->response->setHeaders(['Content-Type' => 'text/html']);
44 44
         }
45 45
         $params = ($this->route->getParameters() == '') ? [] : $this->route->getParameters();
46
-        if (is_array($content = call_user_func_array($this->route->getTarget('closure'), $params))) $this->route->addTarget('data', $content);
47
-        elseif (!is_null($content)) $this->response->setContent($content);
46
+        if (is_array($content = call_user_func_array($this->route->getTarget('closure'), $params))) {
47
+            $this->route->addTarget('data', $content);
48
+        } elseif (!is_null($content)) {
49
+            $this->response->setContent($content);
50
+        }
48 51
     }
49 52
 
50 53
 }
Please login to merge, or discard this patch.
src/Routing/Dispatcher/ControllerDispatcher.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@
 block discarded – undo
72 72
     {
73 73
         $reflector = new ReflectionClass($this->route->getTarget('controller'));
74 74
         if (!$reflector->isInstantiable())
75
-            throw new \Exception('Target [' . $this->route->getTarget('controller') . '] is not instantiable.');
75
+            throw new \Exception('Target ['.$this->route->getTarget('controller').'] is not instantiable.');
76 76
         $constructor = $reflector->getConstructor();
77 77
         if (is_null($constructor)) {
78 78
             $class = $this->route->getTarget('controller');
Please login to merge, or discard this patch.
Braces   +12 added lines, -7 removed lines patch added patch discarded remove patch
@@ -50,17 +50,21 @@  discard block
 block discarded – undo
50 50
         }
51 51
         if ($count == count($this->route->getParameters()) || ($this->route->getParameters() == '' && $count == 0)) {
52 52
             $dependencies = array_merge($dependencies, ($this->route->getParameters() == '') ? [] : $this->route->getParameters());
53
-            if ($this->response->getStatusCode() == 202)
54
-                $this->response->setStatusCode(200);
53
+            if ($this->response->getStatusCode() == 202) {
54
+                            $this->response->setStatusCode(200);
55
+            }
55 56
             if (is_array($content = $reflectionMethod->invokeArgs($this->getController(), $dependencies))) {
56 57
                 $this->route->addTarget('data', $content);
57 58
                 if (isset($this->route->getParams()['ajax']) && $this->route->getParams()['ajax'] === true) {
58 59
                     $this->response->setContent(json_encode($content));
59 60
                     $this->response->setHeaders(['Content-Type' => 'application/json']);
60 61
                 }
61
-            } elseif (!is_null($content)) $this->response->setContent($content);
62
-        } else
63
-            $this->response->setStatusCode(404);
62
+            } elseif (!is_null($content)) {
63
+                $this->response->setContent($content);
64
+            }
65
+        } else {
66
+                    $this->response->setStatusCode(404);
67
+        }
64 68
     }
65 69
 
66 70
 
@@ -71,8 +75,9 @@  discard block
 block discarded – undo
71 75
     private function getController()
72 76
     {
73 77
         $reflector = new ReflectionClass($this->route->getTarget('controller'));
74
-        if (!$reflector->isInstantiable())
75
-            throw new \Exception('Target [' . $this->route->getTarget('controller') . '] is not instantiable.');
78
+        if (!$reflector->isInstantiable()) {
79
+                    throw new \Exception('Target [' . $this->route->getTarget('controller') . '] is not instantiable.');
80
+        }
76 81
         $constructor = $reflector->getConstructor();
77 82
         if (is_null($constructor)) {
78 83
             $class = $this->route->getTarget('controller');
Please login to merge, or discard this patch.