public static function filter_by_request() { $routes = Main::get_instance()->routes; if (!$routes) { return; } return \_u::find($routes, function ($route) { return $route->method->equalsCurrent() && ($route->path->equalsCurrent() || $route->path->matchParams()) && Agent::matchesCurrent($route->agent); }); }
public static function matchesCurrent($agent) { // if user did not specify agent, return like it's found if (!isset($agent)) { return true; } $real_agent = Main::get_instance()->current_request->real_agent; if (is_array($agent)) { return \_u::any($agent, function ($agt) use($real_agent) { return preg_match($agt->value, $real_agent); }); } else { return preg_match($agent->value, $real_agent); } }
public function equalsCurrent() { return $this->value === Main::get_instance()->current_request->method->value; }
/** * Set splats from current request path. * /a/b/[:star:]/f/g/[:star:]/x/y */ public function set_splats_params() { $current_path = Main::get_instance()->current_request->path->value; $splat_path = ''; $ud_index = 0; $splat_index = 0; $current_path_dirs = explode('/', $current_path); $this->splats[0] = ''; foreach ($current_path_dirs as $key => $cur_dir) { $ud_dir = $this->dirs[$ud_index]; @($next_ud_dir = $this->dirs[$ud_index + 1]); if ($cur_dir == $next_ud_dir && @$is_splat_region) { $ud_index += 2; $splat_index += 1; $this->splats[$splat_index] = ''; $is_splat_region = false; continue; } if ($cur_dir == $ud_dir) { $ud_index += 1; $is_splat_region = false; } else { if (Path::is_param($ud_dir) || Path::is_param($ud_dir, true)) { $ud_index += 1; $is_splat_region = false; $this->add_param(trim($ud_dir, ':?'), $cur_dir); } else { if ($ud_dir == '*') { $is_splat_region = true; $this->splats[$splat_index] .= $cur_dir . '/'; } } } } $this->splats = array_filter($this->splats); $this->splats = \_u::map($this->splats, function ($el) { return trim($el, '/'); }); }