Example #1
0
 /**
  * @param $uri
  * @return Route
  */
 public function detectRouteForUri($uri)
 {
     $this->_currentRoute = Route::createNotFoundInstance();
     $this->_currentRoute->setRequest($this->_currentRequest);
     if ($uri && $uri[0] !== '/') {
         $uri = '/' . $uri;
     }
     $this->_currentUri = $uri;
     if (strpos($uri, $this->_webRoot) !== 0) {
         $this->_currentRoute->setName('webRootNotFound');
         return $this->_currentRoute;
     }
     foreach ($this->_routes as $routeName => $routeConfig) {
         $match = UriService::matchPatternToUri($routeConfig['pattern'], $uri, $routeConfig);
         if ($match) {
             $this->_currentRoute = new Route($routeName, $routeConfig['pattern'], $routeConfig);
             $this->_currentRoute->setRequest($this->_currentRequest);
             $this->_currentRoute->setVars($match);
             break;
         }
     }
     return $this->_currentRoute;
 }