2
2
3
3
namespace Buki \Router ;
4
4
5
+ use Closure ;
6
+ use ReflectionException ;
5
7
use ReflectionFunction ;
6
8
use ReflectionMethod ;
7
9
use Reflector ;
@@ -33,17 +35,17 @@ class RouterCommand
33
35
/**
34
36
* @var Request
35
37
*/
36
- private $ request ;
38
+ protected $ request ;
37
39
38
40
/**
39
41
* @var Response
40
42
*/
41
- private $ response ;
43
+ protected $ response ;
42
44
43
45
/**
44
46
* @var array
45
47
*/
46
- private $ middlewares = [];
48
+ protected $ middlewares = [];
47
49
48
50
/**
49
51
* RouterCommand constructor.
@@ -236,11 +238,11 @@ protected function resolveClass(string $class, string $path, string $namespace)
236
238
}
237
239
238
240
/**
239
- * @param array|\ Closure $function
240
- * @param array $params
241
+ * @param array|Closure $function
242
+ * @param array $params
241
243
*
242
244
* @return Response|mixed
243
- * @throws \ ReflectionException
245
+ * @throws ReflectionException
244
246
*/
245
247
protected function runMethodWithParams ($ function , array $ params )
246
248
{
@@ -262,9 +264,9 @@ protected function resolveCallbackParameters(Reflector $reflection, array $uriPa
262
264
{
263
265
$ parameters = [];
264
266
foreach ($ reflection ->getParameters () as $ key => $ param ) {
265
- if (!is_null ($ param ->getClass ()) && $ param ->getClass ()->getName () === Request::class ) {
267
+ if (!is_null ($ param ->getClass ()) && $ param ->getClass ()->getName () instanceof Request) {
266
268
$ parameters [] = $ this ->request ;
267
- } elseif (!is_null ($ param ->getClass ()) && $ param ->getClass ()->getName () === Response::class ) {
269
+ } elseif (!is_null ($ param ->getClass ()) && $ param ->getClass ()->getName () instanceof Response) {
268
270
$ parameters [] = $ this ->response ;
269
271
} elseif (!is_null ($ param ->getClass ())) {
270
272
$ parameters [] = null ;
@@ -287,7 +289,7 @@ protected function resolveCallbackParameters(Reflector $reflection, array $uriPa
287
289
* @param $info
288
290
*
289
291
* @return bool|RouterException
290
- * @throws \ ReflectionException
292
+ * @throws ReflectionException
291
293
*/
292
294
protected function runMiddleware (string $ command , string $ middleware , array $ params , array $ info )
293
295
{
@@ -334,15 +336,15 @@ protected function resolveMiddleware(string $middleware)
334
336
protected function sendResponse ($ response )
335
337
{
336
338
if (is_array ($ response )) {
337
- $ this ->response ->headers ->set ('Content-Type ' , 'application/json ' );;
339
+ $ this ->response ->headers ->set ('Content-Type ' , 'application/json ' );
338
340
return $ this ->response
339
341
->setContent (json_encode ($ response ))
340
342
->prepare ($ this ->request )
341
343
->send ();
342
344
}
343
345
344
346
if (!is_string ($ response )) {
345
- return $ response ;
347
+ return $ response instanceof Response ? $ response -> send () : print ( $ response ) ;
346
348
}
347
349
348
350
return $ this ->response ->setContent ($ response )->prepare ($ this ->request )->send ();
0 commit comments