示例#1
0
 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);
     });
 }
示例#2
0
 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);
         }
     }
 }
示例#3
0
 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);
     }
 }
示例#4
0
 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;
     });
 }
示例#5
0
 public function getInstance()
 {
     if (!isset(self::$_instance)) {
         $c = __CLASS__;
         self::$_instance = new $c();
     }
     return self::$_instance;
 }
示例#6
0
 /**
  * Set $_GET params.
  */
 public function set_params_gets()
 {
     \_u::each($this->params, function ($param, $index) {
         $_GET[$index] = $param;
     });
 }