public function dispatch(RequestFactoryInterface $requestFactory) { $uri = $requestFactory->get()->toArray(); $helper = DispatcherHelper::getHelper($uri); $builtRequest = $this->getBuilder()->controller($helper->getController())->action($helper->getAction())->parameters($helper->getParameters())->build(); $controllerInstance = ClassUtils::load($builtRequest->controller, array($requestFactory->get())); return $this->invoke($controllerInstance, $builtRequest->action, $builtRequest->parameters); }
public function testShouldBuildRouteToRequest() { // Simulates a GET request $_SERVER["SCRIPT_NAME"] = "http://localhost/app/index.php"; $_SERVER["REQUEST_URI"] = "http://localhost/app/pt-br/test/test/attribute1/attribute2"; $_SERVER["REQUEST_METHOD"] = "GET"; $requestFactory = new RequestFactory(); $dispatcherHelper = DispatcherHelper::getHelper($requestFactory->get()->toArray(), true); $localeFinder = FinderFactory::getLocaleFinder($requestFactory); $controllerFinder = FinderFactory::getControllerFinder($requestFactory); $actionFinder = FinderFactory::getActionFinder($requestFactory); $parameterFinder = FinderFactory::getParameterFinder($requestFactory); $routeBuilder = new I18nRouteBuilder($localeFinder, $controllerFinder, $actionFinder, $parameterFinder); $route = $routeBuilder->locale($dispatcherHelper->getLocale())->controller($dispatcherHelper->getController())->action($dispatcherHelper->getAction())->parameters($dispatcherHelper->getParameters())->build(); $this->assertThat($route->locale, $this->equalTo("pt_br"), "Locale is not translated correctly!"); $this->assertThat($route->controller, $this->equalTo("TestController"), "Controller is not translated correctly!"); $this->assertThat($route->action, $this->equalTo("testAction"), "Action is not translated correctly!"); $this->assertThat($route->parameters[0], $this->logicalNot($this->isNull()), "Parameter 1 is not translated correctly!"); $this->assertThat($route->parameters[1], $this->logicalNot($this->isNull()), "Parameter 2 is not translated correctly!"); }