コード例 #1
0
ファイル: RouteCompiler.php プロジェクト: hecrj/sea_core
 public function compile(RouteInterface $route)
 {
     $name = $route->getName();
     if (!$this->isCached($name)) {
         $this->compiled[$name] = $this->doCompile($route);
     }
     return $this->compiled[$name];
 }
コード例 #2
0
ファイル: RouteCollection.php プロジェクト: slince/routing
 /**
  * 添加路由
  * @param RouteInterface $route
  * @param string|null $name
  */
 function add(RouteInterface $route, $name = null)
 {
     if (!is_null($name)) {
         $this->names[$name] = $route;
     }
     $action = $route->getAction();
     if (is_scalar($action)) {
         $this->actions[$action] = $route;
     }
     $this->routes[] = $route;
 }
コード例 #3
0
ファイル: RouteStore.php プロジェクト: slince/router
 /**
  * 添加route
  *
  * @param RouteInterface $route            
  */
 function add(RouteInterface $route)
 {
     if ($route->hasParameter('name')) {
         $routeKey = $route->getParameter('name');
         $this->_names[$routeKey] = $route;
     }
     $action = $route->getParameter('action');
     if (!empty($action) && is_string($action)) {
         $routeKey = $route->getPrefix() . '/' . $action;
         $this->_actions[$routeKey] = $route;
     }
 }
コード例 #4
0
ファイル: Router.php プロジェクト: sugiphp/routing
 /**
  * Adds a route to the end of the list.
  *
  * @param string $name The route's name
  * @param RouteInterface $route
  *
  * @return Router
  */
 public function add($name, RouteInterface $route)
 {
     // clear it
     unset($this->routes[$name]);
     // Name the route
     $route->setDefault("_name", $name);
     // and Router
     $route->setDefault("_router", $this);
     // add it to the bottom of the list
     $this->routes[$name] = $route;
     return $this;
 }
コード例 #5
0
ファイル: Routes.php プロジェクト: lucidphp/mux
 /**
  * {@inheritdoc}
  */
 public function add($routeName, RouteInterface $route)
 {
     if (!is_string($routeName)) {
         throw new \InvalidArgumentException('Routename must be string.');
     }
     $this->routes[$routeName] =& $route;
     foreach ($route->getMethods() as $method) {
         $this->methodIndex[$method][$routeName] = true;
     }
     foreach ($route->getSchemes() as $scheme) {
         $this->schemeIndex[$scheme][$routeName] = true;
     }
 }
コード例 #6
0
ファイル: Router.php プロジェクト: mejinke/powernote
 /**
  * 根据请求指派路由
  *
  * @param \Powernote\Net\Request $request
  * @param bool $resetRouted 重置之前可能存在的路由结果【重新路由】
  * @return \Powernote\Net\Response|null
  */
 public function dispatch(\Powernote\Net\Request $request, $resetRouted = false)
 {
     // 如果之前已成功匹配到路由则直接返回上次匹配到的路由
     if ($this->routed instanceof RouteInterface && $resetRouted === false) {
         return $this->routed->response();
     }
     // 如果路由器列表为空则直接返回
     if ($this->isEmpty()) {
         return null;
     }
     // 只保留问号左侧的Path信息
     $request->url = current(explode('?', $request->url));
     // 优先处理组路由
     $routes = $this->matchGroup($request);
     // 如果没有设置任何路由则返回空
     if (count($routes) == 0) {
         return null;
     }
     // 遍历所有的路由,如果匹配成功则返回该路由
     foreach ($routes as $route) {
         if ($route->match($request)) {
             $this->routed = $route;
             return $this->routed->response();
         }
     }
     return null;
 }
コード例 #7
0
ファイル: Router.php プロジェクト: arabcoders/router
 public function map($rule, array $target = [], array $conditions = [], array $options = [])
 {
     if (empty($this->routeClass)) {
         $this->routeClass = new Route();
     }
     /**
      * @var route $route
      */
     $route = $this->routeClass->route(['rule' => $rule, 'request' => $this->requestUri, 'target' => $target, 'conditions' => $conditions, 'options' => $options]);
     if ($route->isMatched()) {
         $this->setRoute($route);
         return true;
     }
     return false;
 }
コード例 #8
0
ファイル: Result.php プロジェクト: AndrewCarterUK/SimpleRoute
 /**
  * {@inheritdoc}
  */
 public function getHandler()
 {
     return $this->route->getHandler();
 }
コード例 #9
0
ファイル: RouteManager.php プロジェクト: nickstuer/EasyRouter
 /**
  * Verifies that the Route matches expected setup.
  *
  * Currently only checks if the http post method is valid.
  * TODO: Check if action is a callable.
  * TODO: Check if route is valid.
  *
  * @param RouteInterface $route
  *
  * @return bool
  */
 protected function isValidRoute(RouteInterface $route)
 {
     $routeHttpMethod = $route->getHttpMethod();
     return in_array($routeHttpMethod, $this->allowedMethods);
 }
コード例 #10
0
ファイル: RouteCollection.php プロジェクト: slince/router
 /**
  * 添加路由
  *
  * @param RouteInterface $route            
  */
 function add(RouteInterface $route)
 {
     $route->setPreifx($this->_prefix);
     $this->_routes[] = $route;
     RouteStore::newInstance()->add($route);
 }