function map()
{
$url = url::strip_query(server::get('request_uri'));
$url = str_replace(rtrim(c::get('router.root'), '/'), '', $url);
$method = r::method();
foreach (self::$routes as $key => $route) {
if (!in_array($method, $route['methods'])) {
continue;
}
$key = str_replace(')', ')?', $key);
$args = array();
$regex = preg_replace_callback('#@([\\w]+)(:([^/\\(\\)]*))?#', function ($matches) use(&$args) {
$args[$matches[1]] = null;
if (isset($matches[3])) {
return '(?P<' . $matches[1] . '>' . $matches[3] . ')';
}
return '(?P<' . $matches[1] . '>[^/\\?]+)';
}, $key);
if (preg_match('#^' . $regex . '(?:\\?.*)?$#i', $url, $matches)) {
foreach ($args as $k => $v) {
self::$params[$k] = array_key_exists($k, $matches) ? urldecode($matches[$k]) : null;
}
return $route['callback'];
}
}
return false;
}