/** * @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; }
/** * @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(); }
private function _bind() { foreach ($this->routes->all() as $route) { $name = $route->getName(); if (!empty($name)) { $this->namedroute[$name] = $route; } } }
/** * @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; } }
/** * @param RouteCollection $collection */ public function addCollection(RouteCollection $collection) { foreach ($collection->all() as $name => $route) { $this->add($name, $route); } }