public function testBasic() { $route = new Route(); $route->setName('products'); $route->setUriPattern('products/{category}/{id}?'); $route->setConfig(array('controller' => 'IndexController')); $url = $route->buildUri(array('category' => 'macbooks', 'id' => 'air')); $this->assertEquals('products/macbooks/air', $url, 'buildUri works fine'); $this->assertEquals('products/', Route::createInstance('products', 'products/')->buildUri(), 'inline creation'); $this->assertEquals('products', $route, '__toString'); }
/** * @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; }