public function match($uri) { if (!preg_match($this->location_rx, $uri, $matches)) { return MatchResult::fail(); } $vars = $this->defaults; foreach ($this->vmap as $index => $vname) { if (isset($matches[$index + 1])) { $vars[$vname] = $matches[$index + 1]; } elseif ($vname == 'suffix') { $vars['suffix'] = ''; } } $vars['uri'] = $uri; $result = preg_replace_callback('~\\$([a-z0-9_]+)~', function ($m) use(&$vars) { $value = $vars[$m[1]]; unset($vars[$m[1]]); return $value; }, $this->result); unset($vars['uri'], $vars['suffix']); $path = trim(preg_replace('~/{2,}~', '/', $result), '/'); return MatchResult::success(new RoutePoint($path, $vars)); }