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