Пример #1
0
 /**
  * @param $requestUrl
  * @param string $requestMethod
  * @return null
  * @throws \Exception
  */
 public function match($requestUrl, $requestMethod = 'GET')
 {
     $isRegexp = false;
     foreach ($this->routes->all() as $route) {
         if (strpos($requestUrl, $route->getNamekey(), 0)) {
             throw new \Exception("Don't use route name key as part of your route");
         }
         if (!in_array($requestMethod, (array) $route->getMethods())) {
             continue;
         }
         $url = $route->getUrl();
         //bind name
         $name = $route->getName();
         if (!empty($name)) {
             $this->namedroute[$name] = $route;
         }
         if (in_array($requestUrl, (array) $url)) {
             $route->dispatch();
             return $route;
         }
         $isRegexp = $this->_PregMatch($url, $requestUrl, $route);
         if (!in_array($requestUrl, (array) $url) && $isRegexp == false) {
             continue;
         }
         $route->dispatch();
         return $route;
     }
     return null;
 }
Пример #2
0
 /**
  * @param string $uri
  *
  * @return Route
  */
 public function resolve($uri)
 {
     $uri = rtrim($uri, '/');
     $uri = empty($uri) ? '/' : $uri;
     /** @var Route $route */
     foreach ($this->routeCollection->all() as $route) {
         var_dump($route->getPattern(), $uri);
         if ($route->getPattern() === $uri) {
             return $route;
         }
     }
     throw new RouteNotFoundException();
 }
Пример #3
0
 private function _bind()
 {
     foreach ($this->routes->all() as $route) {
         $name = $route->getName();
         if (!empty($name)) {
             $this->namedroute[$name] = $route;
         }
     }
 }
Пример #4
0
 /**
  * @param $requestUrl
  * @param string $requestMethod
  * @return mixed
  * @throws \Exception
  */
 public function match($requestUrl, $requestMethod = 'GET')
 {
     $isRegexp = false;
     foreach ($this->routes->all() as $route) {
         $url = $route->getUrl();
         if (in_array($requestUrl, (array) $url)) {
             $route->dispatch();
             return $route;
         }
         if (!in_array($requestMethod, (array) $route->getMethods())) {
             continue;
         }
         $isRegexp = $this->_PregMatch($url, $requestUrl, $route);
         if (!in_array($requestUrl, (array) $url) && $isRegexp == false) {
             continue;
         }
         $route->dispatch();
         return $route;
     }
 }
Пример #5
0
 /**
  * @param RouteCollection $collection
  */
 public function addCollection(RouteCollection $collection)
 {
     foreach ($collection->all() as $name => $route) {
         $this->add($name, $route);
     }
 }