function route_match($routes, $request) { foreach ($routes as $route) { $method_matches = (is_equal($request['method'], $route['method']) or is_equal('', $route['method'])); foreach ($route['paths'] as $path) { if ($path_matches = path_match($path, $request['path'], $matches)) { break; } } if (isset($route['conds']['action']) and isset($request['form']['action'])) { $action_matches = is_equal($route['conds']['action'], valid_action($request['form']['action'])); } elseif (isset($route['conds']['action']) and !isset($request['form']['action'])) { $action_matches = false; } else { $action_matches = true; } if ($method_matches and $path_matches and $action_matches) { //$rpath_matches['0'] should be equal to 'foo' for '/foo/bar' and $rpath_matches['1'] should be 'bar' $route['path_matches'] = $matches; return $route; } } return false; }
function handler_match_($handler, $req, &$matches = NULL) { $method_matched = (is_equal($req['method'], $handler['method']) or is_equal('*', $handler['method'])); foreach ($handler['paths'] as $path) { if ($path_matched = path_match($path, $req['path'], $matches)) { break; } } $action_cond_failed = (isset($handler['conds']['action']) and (!isset($req['form']['action']) or !is_equal($handler['conds']['action'], strtolower(str_underscorize($req['form']['action']))))); $query_cond_failed = (isset($handler['conds']['query']) and is_equal(true, $handler['conds']['query']) and empty($req['query'])); if ($method_matched and $path_matched and !$action_cond_failed and !$query_cond_failed) { return $handler; } }