Commit | Line | Data |
---|---|---|
7d0df713 S |
1 | <?php |
2 | namespace dns\system\route; | |
43bc7b62 S |
3 | use Zend\Router\Http\Regex as RegexBase; |
4 | use Zend\Router\Http\RouteMatch; | |
8ea73456 | 5 | use Zend\Stdlib\RequestInterface as Request; |
7d0df713 S |
6 | |
7 | class Regex extends RegexBase { | |
8ea73456 | 8 | public function match(Request $request, $pathOffset = null) { |
f0f86c22 | 9 | if (!method_exists($request, 'getPath')) { |
8ea73456 S |
10 | return; |
11 | } | |
f0f86c22 S |
12 | |
13 | $path = $request->getPath(); | |
7d0df713 | 14 | |
8ea73456 S |
15 | if ($pathOffset !== null) { |
16 | $result = preg_match('(\G' . $this->regex . ')i', $path, $matches, null, $pathOffset); | |
17 | } | |
18 | else { | |
19 | $result = preg_match('(^' . $this->regex . '$)i', $path, $matches); | |
20 | } | |
7d0df713 | 21 | |
8ea73456 S |
22 | if (!$result) { |
23 | return; | |
24 | } | |
7d0df713 | 25 | |
8ea73456 | 26 | $matchedLength = strlen($matches[0]); |
7d0df713 | 27 | |
8ea73456 S |
28 | foreach ($matches as $key => $value) { |
29 | if (is_numeric($key) || is_int($key) || $value === '') { | |
30 | unset($matches[$key]); | |
31 | } | |
32 | else { | |
33 | $matches[$key] = rawurldecode($value); | |
34 | } | |
35 | } | |
7d0df713 | 36 | |
8ea73456 S |
37 | return new RouteMatch(array_merge($this->defaults, $matches), $matchedLength); |
38 | } | |
7d0df713 | 39 | } |