public function testRouteWithModule() { Routes::get('/News/:news_id/Articles/:article_id', ['module' => 'Entry', 'controller' => 'NewsArticle', 'action' => 'show']); $route = Routes::getInstance()->parse('GET', '/News/technology/Articles/123'); $this->assertEquals('Entry', $route['module']); $this->assertEquals('NewsArticle', $route['controller']); $this->assertEquals('show', $route['action']); $this->assertEquals(['news_id' => 'technology', 'article_id' => '123'], $route['args']); }
private function routingHandler() { $routes = Config::routes(); Router::$patterns = $routes['pattern']; Router::$defaults = $routes['defaults']; foreach ($routes['route'] as $name => $route) { $class = $route['controller']; $method = $route['action']; unset($route['controller'], $route['action']); Router::route($name, $route, ['class' => $class, 'method' => $method]); } $uriComponents = ['host' => $this->uri->getHost(), 'port' => $this->uri->getPort(), 'method' => $this->uri->getRequestMethod(), 'scheme' => $this->uri->getScheme(), 'path' => '/' . $this->uri->getPathInfo()]; // match if ($result = Router::find($uriComponents)) { try { $instance = new $result['class'](); } catch (LoaderException $e) { if ($nextHandler = next($this->requstHandler)) { $this->{$nextHandler}(); return; } else { $this->throwHTTPException(); } } $variables = Router::$variables; unset($variables['method'], $variables['protocol'], $variables['subdomain'], $variables['domain'], $variables['port']); $args = array_values($variables); $this->run($instance, $result['method'], $args); } else { if ($nextHandler = next($this->requstHandler)) { $this->{$nextHandler}(); return; } else { $this->throwHTTPException(); } } }