@@ -24,11 +24,11 @@ class Route extends RouteCollector
2424 protected $ currentRoute = null ;
2525
2626 /**
27- * The query names for the route.
28- *
29- * @var string[]
27+ * The args names for the route.
28+ *
29+ * @var object
3030 */
31- private $ query = [] ;
31+ protected $ args ;
3232
3333 /**
3434 * All of the verbs supported by the router.
@@ -39,18 +39,15 @@ class Route extends RouteCollector
3939
4040 public function __construct ()
4141 {
42- $ this ->req = $ this ->request ();
43- $ this ->method = $ this ->req ->method ;
44- $ this ->path = $ this ->req ->path ;
45- $ this ->query = $ this ->req ->query ;
42+ $ this ->args = $ this ->request_url ();
4643 }
4744
4845 public function call ()
4946 {
50- $ routes = $ this ->filter_routes_by_method (self ::$ routes , $ this ->method );
47+ $ routes = $ this ->filter_routes_by_method (self ::$ routes , $ this ->args -> method );
5148
5249 foreach ($ routes as $ value ) {
53- if ($ this ->matches ($ value ["uri " ], $ this ->path )) {
50+ if ($ this ->matches ($ value ["uri " ], $ this ->args -> path )) {
5451 $ this ->currentRoute = (object ) $ value ;
5552 break 1 ;
5653 }
@@ -59,13 +56,8 @@ public function call()
5956 if (!$ this ->currentRoute ) {
6057 return Response::json (HttpException::HttpNotFoundException ());
6158 }
62-
63- $ args = (object )[
64- "params " => $ this ->params ,
65- "query " => (object ) $ this ->query
66- ];
67-
68- return call_user_func ($ this ->currentRoute ->callback , (new Request ($ args )));
59+ $ this ->args ->params = $ this ->params ;
60+ return call_user_func ($ this ->currentRoute ->callback , (new Request ($ this ->args )));
6961 }
7062
7163 /**
@@ -106,7 +98,7 @@ private function matches(string $uri, string $path)
10698 return false ;
10799 }
108100
109- private function request ()
101+ private function request_url ()
110102 {
111103 $ httpMethod = $ _SERVER ["REQUEST_METHOD " ] ?? null ;
112104
@@ -120,12 +112,12 @@ private function request()
120112 return Response::json (HttpException::HttpBadRequestException ());
121113 }
122114
123- parse_str ($ _SERVER ["QUERY_STRING " ], $ qs );
115+ parse_str ($ _SERVER ["QUERY_STRING " ] ?? "" , $ qs );
124116
125- return ((object ) array_merge (parse_url ($ URL ), [
117+ return (object ) array_merge (parse_url ($ URL ), [
118+ "url " => $ URL ,
126119 "method " => $ httpMethod ,
127120 "query " => (object )$ qs ,
128- "contentType " => ($ _SERVER ["CONTENT_TYPE " ]) ?? null
129- ]));
121+ ]);
130122 }
131123}
0 commit comments