11
11
*/
12
12
namespace Buki ;
13
13
14
+ use ReflectionMethod ;
14
15
use Buki \Router \RouterRequest ;
15
16
use Buki \Router \RouterCommand ;
16
17
use Buki \Router \RouterException ;
17
18
18
19
class Router
19
20
{
21
+ /**
22
+ * @var $baseFolder Pattern definations for parameters of Route
23
+ */
20
24
protected $ baseFolder ;
21
25
26
+ /**
27
+ * @var $routes Routes list
28
+ */
22
29
protected $ routes = [];
23
- protected $ middlewares = [];
30
+
31
+ /**
32
+ * @var $groups List of group routes
33
+ */
24
34
protected $ groups = [];
25
35
36
+ /**
37
+ * @var $patterns Pattern definations for parameters of Route
38
+ */
26
39
protected $ patterns = [
27
40
'{a} ' => '([^/]+) ' ,
28
41
'{d} ' => '([0-9]+) ' ,
@@ -33,59 +46,88 @@ class Router
33
46
'{*} ' => '(.*) '
34
47
];
35
48
49
+ /**
50
+ * @var $namespaces Namespaces of Controllers and Middlewares files
51
+ */
36
52
protected $ namespaces = [
37
53
'middlewares ' => '' ,
38
54
'controllers ' => ''
39
55
];
40
56
57
+ /**
58
+ * @var $path Paths of Controllers and Middlewares files
59
+ */
41
60
protected $ paths = [
42
61
'controllers ' => 'Controllers ' ,
43
62
'middlewares ' => 'Middlewares '
44
63
];
45
64
65
+ /**
66
+ * @var $mainMethod Main method for controller
67
+ */
68
+ protected $ mainMethod = 'main ' ;
69
+
46
70
protected $ errorCallback ;
47
71
48
72
/**
49
73
* Router constructer method.
74
+ *
75
+ * @param array $params
50
76
*
51
- * @return
77
+ * @return void
52
78
*/
53
- function __construct (Array $ params = [])
79
+ function __construct (array $ params = [])
54
80
{
55
81
$ this ->baseFolder = realpath (getcwd ());
56
82
57
- if ( is_null ( $ params ) || empty ($ params )) {
83
+ if ( empty ($ params )) {
58
84
return ;
59
85
}
60
86
61
- if (isset ($ params ['debug ' ]) && is_bool ($ params ['debug ' ])) {
87
+ if (isset ($ params ['debug ' ]) && is_bool ($ params ['debug ' ])) {
62
88
RouterException::$ debug = $ params ['debug ' ];
63
89
}
64
90
65
- if (isset ($ params ['paths ' ]) && $ paths = $ params ['paths ' ]) {
66
- $ this ->paths ['controllers ' ] = (
67
- isset ($ paths ['controllers ' ]) ? $ this ->baseFolder . '/ ' . trim ($ paths ['controllers ' ], '/ ' ) . '/ ' : $ this ->paths ['controllers ' ]
68
- );
69
- $ this ->paths ['middlewares ' ] = (
70
- isset ($ paths ['middlewares ' ]) ? $ this ->baseFolder . '/ ' . trim ($ paths ['middlewares ' ], '/ ' ) . '/ ' : $ this ->paths ['middlewares ' ]
71
- );
91
+ $ this ->setPaths ($ params );
92
+ }
93
+
94
+ /**
95
+ * Set paths and namespaces for Controllers and Middlewares.
96
+ *
97
+ * @return void
98
+ */
99
+ protected function setPaths ($ params )
100
+ {
101
+ if (isset ($ params ['paths ' ]) && $ paths = $ params ['paths ' ]) {
102
+ $ this ->paths ['controllers ' ] =
103
+ isset ($ paths ['controllers ' ])
104
+ ? trim ($ paths ['controllers ' ], '/ ' )
105
+ : $ this ->paths ['controllers ' ];
106
+
107
+ $ this ->paths ['middlewares ' ] =
108
+ isset ($ paths ['middlewares ' ])
109
+ ? trim ($ paths ['middlewares ' ], '/ ' )
110
+ : $ this ->paths ['middlewares ' ];
72
111
}
73
112
74
- if (isset ($ params ['namespaces ' ]) && $ namespaces = $ params ['namespaces ' ]) {
75
- $ this ->namespaces ['controllers ' ] = (
76
- isset ($ namespaces ['controllers ' ]) ? trim ($ namespaces ['controllers ' ], '\\' ) . '\\' : ''
77
- );
78
- $ this ->namespaces ['middlewares ' ] = (
79
- isset ($ namespaces ['middlewares ' ]) ? trim ($ namespaces ['middlewares ' ], '\\' ) . '\\' : ''
80
- );
113
+ if (isset ($ params ['namespaces ' ]) && $ namespaces = $ params ['namespaces ' ]) {
114
+ $ this ->namespaces ['controllers ' ] =
115
+ isset ($ namespaces ['controllers ' ])
116
+ ? trim ($ namespaces ['controllers ' ], '\\' ) . '\\'
117
+ : '' ;
118
+
119
+ $ this ->namespaces ['middlewares ' ] =
120
+ isset ($ namespaces ['middlewares ' ])
121
+ ? trim ($ namespaces ['middlewares ' ], '\\' ) . '\\'
122
+ : '' ;
81
123
}
82
124
}
83
125
84
126
/**
85
127
* Add route method;
86
128
* Get, Post, Put, Delete, Patch, Any, Ajax...
87
129
*
88
- * @return
130
+ * @return void
89
131
*/
90
132
public function __call ($ method , $ params )
91
133
{
@@ -101,29 +143,30 @@ public function __call($method, $params)
101
143
$ callback = $ params [1 ];
102
144
$ settings = null ;
103
145
104
- if (count ($ params ) > 2 ) {
146
+ if (count ($ params ) > 2 ) {
105
147
$ settings = $ params [1 ];
106
148
$ callback = $ params [2 ];
107
149
}
108
150
109
- if (strstr ($ route , '{ ' )) {
151
+ if (strstr ($ route , '{ ' )) {
110
152
$ route1 = $ route2 = '' ;
111
- foreach (explode ('/ ' , $ route ) as $ key => $ value ) {
112
- if ($ value != '' ) {
113
- if (! strpos ($ value , '? ' )) {
153
+ foreach (explode ('/ ' , $ route ) as $ key => $ value ) {
154
+ if ($ value != '' ) {
155
+ if (! strpos ($ value , '? ' )) {
114
156
$ route1 .= '/ ' . $ value ;
115
157
} else {
116
- if ($ route2 == '' ) {
158
+ if ($ route2 == '' ) {
117
159
$ this ->addRoute ($ route1 , $ method , $ callback , $ settings );
118
160
}
161
+
119
162
$ route2 = $ route1 . '/ ' . str_replace ('? ' , '' , $ value );
120
163
$ this ->addRoute ($ route2 , $ method , $ callback , $ settings );
121
164
$ route1 = $ route2 ;
122
165
}
123
166
}
124
167
}
125
168
126
- if ($ route2 == '' ) {
169
+ if ($ route2 == '' ) {
127
170
$ this ->addRoute ($ route1 , $ method , $ callback , $ settings );
128
171
}
129
172
} else {
@@ -135,18 +178,23 @@ public function __call($method, $params)
135
178
/**
136
179
* Add new route method one or more http methods.
137
180
*
138
- * @return null
181
+ * @param string $methods
182
+ * @param string $route
183
+ * @param array|string|closure $settings
184
+ * @param string|closure $callback
185
+ *
186
+ * @return void
139
187
*/
140
188
public function add ($ methods , $ route , $ settings , $ callback = null )
141
189
{
142
- if (is_null ($ callback )) {
190
+ if (is_null ($ callback )) {
143
191
$ callback = $ settings ;
144
192
$ settings = null ;
145
193
}
146
194
147
- if (strstr ($ methods , '| ' )) {
195
+ if (strstr ($ methods , '| ' )) {
148
196
foreach (array_unique (explode ('| ' , $ methods )) as $ method ) {
149
- if ($ method != '' ) {
197
+ if ($ method != '' ) {
150
198
call_user_func_array ([$ this , strtolower ($ method )], [$ route , $ settings , $ callback ]);
151
199
}
152
200
}
@@ -160,20 +208,23 @@ public function add($methods, $route, $settings, $callback = null)
160
208
/**
161
209
* Add new route rules pattern; String or Array
162
210
*
163
- * @return
211
+ * @param string|array $pattern
212
+ * @param null|string $attr
213
+ *
214
+ * @return void
164
215
*/
165
216
public function pattern ($ pattern , $ attr = null )
166
217
{
167
- if (is_array ($ pattern )) {
218
+ if (is_array ($ pattern )) {
168
219
foreach ($ pattern as $ key => $ value ) {
169
- if (! in_array ('{ ' . $ key . '} ' , array_keys ($ this ->patterns ))) {
220
+ if (! in_array ('{ ' . $ key . '} ' , array_keys ($ this ->patterns ))) {
170
221
$ this ->patterns ['{ ' . $ key . '} ' ] = '( ' . $ value . ') ' ;
171
222
} else {
172
223
return $ this ->exception ($ key . ' pattern cannot be changed. ' );
173
224
}
174
225
}
175
226
} else {
176
- if (! in_array ('{ ' . $ pattern . '} ' , array_keys ($ this ->patterns ))) {
227
+ if (! in_array ('{ ' . $ pattern . '} ' , array_keys ($ this ->patterns ))) {
177
228
$ this ->patterns ['{ ' . $ pattern . '} ' ] = '( ' . $ attr . ') ' ;
178
229
} else {
179
230
return $ this ->exception ($ pattern . ' pattern cannot be changed. ' );
@@ -183,20 +234,11 @@ public function pattern($pattern, $attr = null)
183
234
return ;
184
235
}
185
236
186
- /**
187
- * Add new middleware
188
- *
189
- * @return null
190
- */
191
- public function middleware ($ name , $ command )
192
- {
193
- $ this ->middlewares [$ name ] = $ command ;
194
- }
195
-
196
237
/**
197
238
* Run Routes
198
239
*
199
- * @return true | throw Exception
240
+ * @return void
241
+ * @throw Exception
200
242
*/
201
243
public function run ()
202
244
{
@@ -206,10 +248,11 @@ public function run()
206
248
$ base = str_replace ('\\' , '/ ' , str_replace ($ documentRoot , '' , $ getCwd ) . '/ ' );
207
249
$ uri = parse_url ($ _SERVER ['REQUEST_URI ' ], PHP_URL_PATH );
208
250
209
- if (($ base != $ uri ) && (substr ($ uri , -1 ) == '/ ' )) {
251
+ if (($ base != $ uri ) && (substr ($ uri , -1 ) == '/ ' )) {
210
252
$ uri = substr ($ uri , 0 , (strlen ($ uri )-1 ));
211
253
}
212
- if ($ uri === '' ) {
254
+
255
+ if ($ uri === '' ) {
213
256
$ uri = '/ ' ;
214
257
}
215
258
@@ -251,7 +294,7 @@ public function run()
251
294
array_shift ($ matched );
252
295
$ newMatched = [];
253
296
foreach ($ matched as $ key => $ value ) {
254
- if (strstr ($ value , '/ ' )) {
297
+ if (strstr ($ value , '/ ' )) {
255
298
foreach (explode ('/ ' , $ value ) as $ k => $ v ) {
256
299
$ newMatched [] = trim (urldecode ($ v ));
257
300
}
@@ -270,12 +313,12 @@ public function run()
270
313
}
271
314
272
315
// If it originally was a HEAD request, clean up after ourselves by emptying the output buffer
273
- if (strtoupper ($ _SERVER ['REQUEST_METHOD ' ]) == 'HEAD ' ) {
316
+ if (strtoupper ($ _SERVER ['REQUEST_METHOD ' ]) === 'HEAD ' ) {
274
317
ob_end_clean ();
275
318
}
276
319
277
320
if ($ foundRoute == false ) {
278
- if (!$ this ->errorCallback ) {
321
+ if (! $ this ->errorCallback ) {
279
322
$ this ->errorCallback = function () {
280
323
header ($ _SERVER ['SERVER_PROTOCOL ' ]." 404 Not Found " );
281
324
return $ this ->exception ('Route not found. Looks like something went wrong. Please try again. ' );
@@ -288,7 +331,11 @@ public function run()
288
331
/**
289
332
* Routes Group
290
333
*
291
- * @return null
334
+ * @param string $name
335
+ * @param closure|array $settings
336
+ * @param null|closure $callback
337
+ *
338
+ * @return void
292
339
*/
293
340
public function group ($ name , $ settings = null , $ callback = null )
294
341
{
@@ -297,32 +344,32 @@ public function group($name, $settings = null, $callback = null)
297
344
$ group ['route ' ] = '/ ' . $ groupName ;
298
345
$ group ['before ' ] = $ group ['after ' ] = null ;
299
346
300
- if (is_null ($ callback )) {
347
+ if (is_null ($ callback )) {
301
348
$ callback = $ settings ;
302
349
} else {
303
350
$ group ['before ' ][] = (!isset ($ settings ['before ' ]) ? null : $ settings ['before ' ]);
304
351
$ group ['after ' ][] = (!isset ($ settings ['after ' ]) ? null : $ settings ['after ' ]);
305
352
}
306
353
307
354
$ groupCount = count ($ this ->groups );
308
- if ($ groupCount > 0 ) {
355
+ if ($ groupCount > 0 ) {
309
356
$ list = [];
310
357
foreach ($ this ->groups as $ key => $ value ) {
311
- if (is_array ($ value ['before ' ])) {
312
- foreach ($ value ['before ' ] as $ k => $ v ) {
358
+ if (is_array ($ value ['before ' ])) {
359
+ foreach ($ value ['before ' ] as $ k => $ v ) {
313
360
$ list ['before ' ][] = $ v ;
314
361
}
315
- foreach ($ value ['after ' ] as $ k => $ v ) {
362
+ foreach ($ value ['after ' ] as $ k => $ v ) {
316
363
$ list ['after ' ][] = $ v ;
317
364
}
318
365
}
319
366
}
320
367
321
- if (! is_null ($ group ['before ' ])) {
368
+ if (! is_null ($ group ['before ' ])) {
322
369
$ list ['before ' ][] = $ group ['before ' ][0 ];
323
370
}
324
371
325
- if (! is_null ($ group ['after ' ])) {
372
+ if (! is_null ($ group ['after ' ])) {
326
373
$ list ['after ' ][] = $ group ['after ' ][0 ];
327
374
}
328
375
@@ -335,7 +382,7 @@ public function group($name, $settings = null, $callback = null)
335
382
336
383
array_push ($ this ->groups , $ group );
337
384
338
- if (is_object ($ callback )) {
385
+ if (is_object ($ callback )) {
339
386
call_user_func_array ($ callback , [$ this ]);
340
387
}
341
388
@@ -345,54 +392,70 @@ public function group($name, $settings = null, $callback = null)
345
392
/**
346
393
* Added route from methods of Controller file.
347
394
*
348
- * @return null
395
+ * @param string $route
396
+ * @param string|array $settings
397
+ * @param null|string $controller
398
+ *
399
+ * @return void
349
400
*/
350
- public function controller ($ route , $ controller )
401
+ public function controller ($ route , $ settings , $ controller = null )
351
402
{
403
+ if (is_null ($ controller )) {
404
+ $ controller = $ settings ;
405
+ $ settings = [];
406
+ }
407
+
352
408
$ controller = str_replace (['\\' , '. ' ], '/ ' , $ controller );
353
409
$ controllerFile = realpath (
354
- $ this ->paths ['controllers ' ] . $ controller . '.php '
410
+ rtrim ( $ this ->paths ['controllers ' ], ' / ' ) . ' / ' . $ controller . '.php '
355
411
);
356
- if (file_exists ($ controllerFile )) {
357
- if (!class_exists ($ controller )) {
358
- $ req = require ($ controllerFile );
359
- }
360
- } else {
361
- return $ this ->exception ($ controller . " controller file is not found! Please, check file. " );
412
+
413
+ if (! file_exists ($ controllerFile )) {
414
+ return $ this ->exception ($ controller . ' class is not found! ' );
415
+ }
416
+
417
+ if (! class_exists ($ controller )) {
418
+ require ($ controllerFile );
362
419
}
363
420
364
421
$ controller = str_replace ('/ ' , '\\' , $ controller );
365
422
$ classMethods = get_class_methods ($ this ->namespaces ['controllers ' ] . $ controller );
366
- if ($ classMethods ) {
423
+ if ($ classMethods ) {
367
424
foreach ($ classMethods as $ methodName ) {
368
- if (! strstr ($ methodName , '__ ' )) {
369
- $ method = " any " ;
370
- foreach (explode ('| ' , RouterRequest::$ validMethods ) as $ m ) {
371
- if (stripos ($ methodName , strtolower ($ m ), 0 ) === 0 ) {
425
+ if (! strstr ($ methodName , '__ ' )) {
426
+ $ method = ' any ' ;
427
+ foreach (explode ('| ' , RouterRequest::$ validMethods ) as $ m ) {
428
+ if (stripos ($ methodName , strtolower ($ m ), 0 ) === 0 ) {
372
429
$ method = strtolower ($ m );
373
430
break ;
374
431
}
375
432
}
376
433
377
434
$ methodVar = lcfirst (str_replace ($ method , '' , $ methodName ));
378
- $ r = new \ReflectionMethod ($ this ->namespaces ['controllers ' ] . $ controller , $ methodName );
379
- $ paramNum = $ r ->getNumberOfRequiredParameters ();
380
- $ paramNum2 = $ r ->getNumberOfParameters ();
381
-
382
- $ value = ($ methodVar == 'main ' ? $ route : $ route . '/ ' . $ methodVar );
383
- $ this ->{$ method }(($ value . str_repeat ('/{a} ' , $ paramNum ) . str_repeat ('/{a?} ' , $ paramNum2 - $ paramNum )), ($ controller . '@ ' . $ methodName ));
435
+ $ r = new ReflectionMethod ($ this ->namespaces ['controllers ' ] . $ controller , $ methodName );
436
+ $ requiredParam = $ r ->getNumberOfRequiredParameters ();
437
+ $ totalParam = $ r ->getNumberOfParameters ();
438
+
439
+ $ value = ($ methodVar === 'main ' ? $ route : $ route . '/ ' . $ methodVar );
440
+
441
+ $ this ->addRoute (
442
+ ($ value .str_repeat ('/{a} ' , $ requiredParam ).str_repeat ('/{a?} ' , $ totalParam -$ requiredParam )),
443
+ $ method ,
444
+ ($ controller .'@ ' .$ methodName ),
445
+ $ settings
446
+ );
384
447
}
385
448
}
386
449
unset($ r );
387
450
}
388
-
389
- $ req = null ;
390
451
}
391
452
392
453
/**
393
454
* Routes error function. (Closure)
394
455
*
395
- * @return null
456
+ * @param $callback
457
+ *
458
+ * @return void
396
459
*/
397
460
public function error ($ callback )
398
461
{
@@ -402,38 +465,59 @@ public function error($callback)
402
465
/**
403
466
* Add new Route and it's settings
404
467
*
405
- * @return null
468
+ * @param $uri
469
+ * @param $method
470
+ * @param $callback
471
+ * @param $settings
472
+ *
473
+ * @return void
406
474
*/
407
475
private function addRoute ($ uri , $ method , $ callback , $ settings )
408
476
{
409
477
$ groupItem = count ($ this ->groups ) - 1 ;
410
478
$ group = '' ;
411
- if ($ groupItem > -1 ) {
479
+ if ($ groupItem > -1 ) {
412
480
foreach ($ this ->groups as $ key => $ value ) {
413
481
$ group .= $ value ['route ' ];
414
482
}
415
483
}
416
484
417
485
$ page = dirname ($ _SERVER ['PHP_SELF ' ]);
418
486
$ page = $ page == '/ ' ? '' : $ page ;
419
- if (strstr ($ page , 'index.php ' )) {
487
+ if (strstr ($ page , 'index.php ' )) {
420
488
$ data = implode ('/ ' , explode ('/ ' , $ page ));
421
489
$ page = str_replace ($ data , '' , $ page );
422
490
}
423
491
424
492
$ route = $ page . $ group . '/ ' . trim ($ uri , '/ ' );
425
493
$ route = rtrim ($ route , '/ ' );
426
- if ($ route == $ page ) {
494
+ if ($ route == $ page ) {
427
495
$ route .= '/ ' ;
428
496
}
429
497
430
498
$ data = [
431
499
'route ' => str_replace ('// ' , '/ ' , $ route ),
432
500
'method ' => strtoupper ($ method ),
433
- 'callback ' => (is_object ($ callback ) ? $ callback : $ this ->namespaces ['controllers ' ] . $ callback ),
434
- 'alias ' => (isset ($ settings ['alias ' ]) ? $ settings ['alias ' ] : (isset ($ settings ['as ' ]) ? $ settings ['as ' ] : null )),
435
- 'before ' => (isset ($ settings ['before ' ]) ? (!is_array ($ settings ['before ' ]) && !is_object ($ settings ['before ' ]) && strstr ($ settings ['before ' ], '@ ' ) ? $ this ->namespaces ['middlewares ' ] . $ settings ['before ' ] : $ settings ['before ' ] ) : null ),
436
- 'after ' => (isset ($ settings ['after ' ]) ? (!is_array ($ settings ['after ' ]) && !is_object ($ settings ['after ' ]) && strstr ($ settings ['after ' ], '@ ' ) ? $ this ->namespaces ['middlewares ' ] . $ settings ['after ' ] : $ settings ['after ' ] ) : null ),
501
+ 'callback ' => (is_object ($ callback )
502
+ ? $ callback
503
+ : $ this ->namespaces ['controllers ' ] . $ callback
504
+ ),
505
+ 'name ' => (isset ($ settings ['name ' ])
506
+ ? $ settings ['name ' ]
507
+ : null
508
+ ),
509
+ 'before ' => (isset ($ settings ['before ' ])
510
+ ? (is_string ($ settings ['before ' ])
511
+ ? $ this ->namespaces ['middlewares ' ] . $ settings ['before ' ]
512
+ : $ settings ['before ' ])
513
+ : null
514
+ ),
515
+ 'after ' => (isset ($ settings ['after ' ])
516
+ ? (is_string ($ settings ['after ' ])
517
+ ? $ this ->namespaces ['middlewares ' ] . $ settings ['after ' ]
518
+ : $ settings ['after ' ])
519
+ : null
520
+ ),
437
521
'group ' => ($ groupItem === -1 ) ? null : $ this ->groups [$ groupItem ]
438
522
];
439
523
array_push ($ this ->routes , $ data );
@@ -447,33 +531,41 @@ private function addRoute($uri, $method, $callback, $settings)
447
531
private function runRouteCommand ($ command , $ params = null )
448
532
{
449
533
$ this ->routerCommand ()->runRoute (
450
- $ command , $ params , $ this ->paths ['controllers ' ], $ this ->namespaces ['controllers ' ]
534
+ $ command ,
535
+ $ params ,
536
+ $ this ->baseFolder . '/ ' . $ this ->paths ['controllers ' ],
537
+ $ this ->namespaces ['controllers ' ]
451
538
);
452
539
}
453
540
454
541
/**
455
542
* Detect Routes Middleware; before or after
456
543
*
457
- * @return null
544
+ * @param $middleware
545
+ * @param $type
546
+ *
547
+ * @return void
458
548
*/
459
549
public function runRouteMiddleware ($ middleware , $ type )
460
550
{
461
- if ($ type == 'before ' ) {
462
- if (!is_null ($ middleware ['group ' ])) {
551
+ $ middlewarePath = $ this ->baseFolder . '/ ' . $ this ->paths ['middlewares ' ];
552
+ $ middlewareNs = $ this ->namespaces ['middlewares ' ];
553
+ if ($ type == 'before ' ) {
554
+ if (! is_null ($ middleware ['group ' ])) {
463
555
$ this ->routerCommand ()->beforeAfter (
464
- $ middleware ['group ' ][$ type ], $ this -> middlewares , $ this -> paths [ ' middlewares ' ], $ this -> namespaces [ ' middlewares ' ]
556
+ $ middleware ['group ' ][$ type ], $ middlewarePath , $ middlewareNs
465
557
);
466
558
}
467
559
$ this ->routerCommand ()->beforeAfter (
468
- $ middleware [$ type ], $ this -> middlewares , $ this -> paths [ ' middlewares ' ], $ this -> namespaces [ ' middlewares ' ]
560
+ $ middleware [$ type ], $ middlewarePath , $ middlewareNs
469
561
);
470
562
} else {
471
563
$ this ->routerCommand ()->beforeAfter (
472
- $ middleware [$ type ], $ this -> middlewares , $ this -> paths [ ' middlewares ' ], $ this -> namespaces [ ' middlewares ' ]
564
+ $ middleware [$ type ], $ middlewarePath , $ middlewareNs
473
565
);
474
- if (! is_null ($ middleware ['group ' ])) {
566
+ if (! is_null ($ middleware ['group ' ])) {
475
567
$ this ->routerCommand ()->beforeAfter (
476
- $ middleware ['group ' ][$ type ], $ this -> middlewares , $ this -> paths [ ' middlewares ' ], $ this -> namespaces [ ' middlewares ' ]
568
+ $ middleware ['group ' ][$ type ], $ middlewarePath , $ middlewareNs
477
569
);
478
570
}
479
571
}
@@ -482,7 +574,7 @@ public function runRouteMiddleware($middleware, $type)
482
574
/**
483
575
* Routes Group endpoint
484
576
*
485
- * @return null
577
+ * @return void
486
578
*/
487
579
private function endGroup ()
488
580
{
@@ -492,11 +584,11 @@ private function endGroup()
492
584
/**
493
585
* Display all Routes.
494
586
*
495
- * @return null
587
+ * @return void
496
588
*/
497
589
public function getList ()
498
590
{
499
- echo '<pre style="border:1px solid #eee;padding:0 10px;width:960px;max-height:780;margin:20px auto; font-size:17px;overflow:auto ;"> ' ;
591
+ echo '<pre style="font-size:15px ;"> ' ;
500
592
var_dump ($ this ->getRoutes ());
501
593
echo '</pre> ' ;
502
594
die ();
@@ -514,6 +606,8 @@ public function getRoutes()
514
606
515
607
/**
516
608
* Throw new Exception for Router Error
609
+ *
610
+ * @param $message
517
611
*
518
612
* @return RouterException
519
613
*/
@@ -528,7 +622,7 @@ public function exception($message = '')
528
622
* @return RouterCommand
529
623
*/
530
624
public function routerCommand ()
531
- {
625
+ {
532
626
return RouterCommand::getInstance ();
533
627
}
534
628
}
0 commit comments