... | ... |
@@ -100,6 +100,16 @@ class Router{ |
100 | 100 |
return $this; |
101 | 101 |
} |
102 | 102 |
|
103 |
+ public function cleanPregMatch($match){ |
|
104 |
+ $cleanMatch = array(); |
|
105 |
+ foreach($match as $key => $value){ |
|
106 |
+ if($value[1]>-1){ |
|
107 |
+ $cleanMatch[$key] = $value[0]; |
|
108 |
+ } |
|
109 |
+ } |
|
110 |
+ return $cleanMatch; |
|
111 |
+ } |
|
112 |
+ |
|
103 | 113 |
public function match($request){ |
104 | 114 |
|
105 | 115 |
$auri = explode('/', trim($request->path, "/ \t\n\r\0\x0B")); |
... | ... |
@@ -147,8 +157,8 @@ class Router{ |
147 | 157 |
$route_pattern = $routeInfo->path; |
148 | 158 |
$method = $routeInfo->method; |
149 | 159 |
if($method=='ANY' || strpos($request->method, $method)!==false){ |
150 |
- if(\preg_match($route_pattern, $request->path, $match)){ |
|
151 |
- $this->parsedParameters = $match; |
|
160 |
+ if(\preg_match($route_pattern, $request->path, $match, \PREG_OFFSET_CAPTURE)){ |
|
161 |
+ $this->parsedParameters = $this->cleanPregMatch($match); |
|
152 | 162 |
$this->depth = $curi; |
153 | 163 |
$this->routeInfo = $routeInfo; |
154 | 164 |
return $routeInfo->result; |