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 function set_all() { foreach ($this->names as $header => $value) { if (strtolower($header) == 'exclude') { \_u::each($value, function ($v, $i) { header_remove($v); }); } else { header($header . ': ' . $value); } } }
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 add_routes() { $routes = func_get_args(); \_u::each($routes, function ($route, $index) { $method = key($route); $items = $route[$method]; if (!Method::has_method(strtolower($method))) { continue; } $route = new Route($items); $route->method = new Method($method); if (isset($items['headers']) && is_array($items['headers'])) { $route->headers = Headers::set_for_route($items['headers']); } $this->routes[] = $route; }); }
public function getInstance() { if (!isset(self::$_instance)) { $c = __CLASS__; self::$_instance = new $c(); } return self::$_instance; }
/** * Set $_GET params. */ public function set_params_gets() { \_u::each($this->params, function ($param, $index) { $_GET[$index] = $param; }); }