1
1
<?php
2
+
2
3
namespace AmazePHP ;
4
+
3
5
use Illuminate \Container \Container ;
4
6
5
7
class Router
@@ -10,6 +12,7 @@ class Router
10
12
private $ routeCount = 0 ;
11
13
protected static $ _nameList = [];
12
14
private $ _path = [];
15
+ private $ container ;
13
16
14
17
public function __construct ()
15
18
{
@@ -81,20 +84,24 @@ public function doRouting()
81
84
preg_match_all ("/{[a-zA-Z0-9\_\-}]+/ " , $ route ['url ' ], $ matches1 );
82
85
83
86
foreach ($ matches1 [0 ] as $ key => $ value ) {
84
- $ matches [trim ($ value ,"{} " )]= $ matches [$ key ] ?? null ;
87
+ $ matches [trim ($ value , "{} " )]= $ matches [$ key ] ?? null ;
85
88
}
86
89
87
90
foreach ($ matches as $ mkey => &$ mvalue ) {
91
+ $ mvalue =trim ((string )$ mvalue , "/ " );
88
92
89
- $ mvalue =trim ( (string )$ mvalue ,"/ " );
90
-
91
- if (is_null ($ mvalue ) || empty ($ mvalue ) ){
93
+ if (is_null ($ mvalue ) || empty ($ mvalue )) {
92
94
unset($ matches [$ mkey ]);
93
95
}
94
96
}
95
97
96
- // echo call_user_func_array($route['callback'], $matches);
97
- echo $ this ->container ->call ($ route ['callback ' ], $ matches );
98
+ if ($ route ['callback ' ] instanceof \Closure) {
99
+ echo $ this ->container ->call ($ route ['callback ' ], $ matches );
100
+ } else {
101
+ $ controller = $ this ->container ->make ($ route ['callback ' ][0 ]);
102
+ // echo call_user_func_array($route['callback'], $matches);
103
+ echo $ this ->container ->call ([$ controller , $ route ['callback ' ][1 ]], $ matches );
104
+ }
98
105
});
99
106
} else {
100
107
$ is_match ++;
@@ -139,9 +146,3 @@ public function name($name)
139
146
return $ this ;
140
147
}
141
148
}
142
-
143
-
144
- //autoload
145
- // spl_autoload_register(function ($class_name) {
146
- // require_once __DIR__ . '/' . str_replace('\\', '/', $class_name) . '.php';
147
- // });
0 commit comments