diff --git a/src/Featon/Test/Test.php b/src/Featon/Test/Test.php new file mode 100755 index 0000000..0cf0f99 --- /dev/null +++ b/src/Featon/Test/Test.php @@ -0,0 +1,9 @@ +request = $request; + + $router = $this->handleRoutes($this->getRoutes()); + $dispatcher = new Dispatcher($router); + $response = $dispatcher->dispatch($request->getMethod(), parse_url($request->getPathInfo(), PHP_URL_PATH)); + + return $response; + } + + protected function handleRoutes(array $routes) + { + $controllers = $this->getControllers($routes); + $router = new RouteCollector(); + + foreach ($routes as $routeDefinition) { + list($controller, $method) = explode(':', $routeDefinition[2]); + $router->{strtolower($routeDefinition[0])}($routeDefinition[1], [$controllers[$controller],$method]); + } + + return $router; + } + + protected function getControllers($routes) + { + $controllers = array(); + + foreach ($routes as $routeDefinition) { + $controllerMethod = array_pop($routeDefinition); + list($controller, $method) = explode(':', $controllerMethod); + + $controllers[$controller] = new $controller($this->request, $this->getTemplateHandler()); + } + + return $controllers; + } +}