/** * Resolve a route for the request * * Stores the resolved route values in the ComponentContext to pass them * to other components. They can be accessed via ComponentContext::getParameter('TYPO3\Flow\Mvc\Routing\RoutingComponent', 'matchResults'); * * @param ComponentContext $componentContext * @return void */ public function handle(ComponentContext $componentContext) { if ($componentContext->getParameter('TYPO3\\Flow\\Mvc\\Routing\\RoutingComponent', 'skipRouterInitialization') !== TRUE) { $routesConfiguration = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_ROUTES); $this->router->setRoutesConfiguration($routesConfiguration); } $matchResults = $this->router->route($componentContext->getHttpRequest()); $componentContext->setParameter('TYPO3\\Flow\\Mvc\\Routing\\RoutingComponent', 'matchResults', $matchResults); }
/** * @param string $path * @return string * @throws \Exception */ public function render($path = NULL) { if ($path === NULL) { $path = '404'; } /** @var RequestHandler $activeRequestHandler */ $activeRequestHandler = $this->bootstrap->getActiveRequestHandler(); $parentHttpRequest = $activeRequestHandler->getHttpRequest(); $requestPath = $parentHttpRequest->getUri()->getPath(); $language = explode('/', ltrim($requestPath, '/'))[0]; if ($language === 'neos') { throw new \Exception('NotFoundViewHelper can not be used for neos-routes.', 1435648210); } $language = $this->localeDetector->detectLocaleFromLocaleTag($language)->getLanguage(); if ($this->contentDimensionPresetSource->findPresetByUriSegment('language', $language) === NULL) { $language = ''; } if ($language !== '') { $language .= '/'; } $request = Request::create(new Uri(rtrim($parentHttpRequest->getBaseUri(), '/') . '/' . $language . $path)); $matchingRoute = $this->router->route($request); if (!$matchingRoute) { throw new \Exception(sprintf('Uri with path "%s" could not be found.', rtrim($parentHttpRequest->getBaseUri(), '/') . '/' . $language . $path), 1426446160); } $response = new Response(); $objectManager = $this->bootstrap->getObjectManager(); $baseComponentChain = $objectManager->get('TYPO3\\Flow\\Http\\Component\\ComponentChain'); $componentContext = new ComponentContext($request, $response); $baseComponentChain->handle($componentContext); return $response->getContent(); }
/** * @param string $path * @return string * @throws \Exception */ public function render($path = NULL) { /** @var RequestHandler $activeRequestHandler */ $activeRequestHandler = $this->bootstrap->getActiveRequestHandler(); $parentHttpRequest = $activeRequestHandler->getHttpRequest(); $httpRequest = Request::create(new Uri($parentHttpRequest->getBaseUri() . $path . '.html')); $matchingRoute = $this->router->route($httpRequest); if (!$matchingRoute) { throw new \Exception(sprintf('Uri with path "%s" could not be found.', $parentHttpRequest->getBaseUri() . $path . '.html'), 1426446160); } $request = new ActionRequest($parentHttpRequest); foreach ($matchingRoute as $argumentName => $argumentValue) { $request->setArgument($argumentName, $argumentValue); } $response = new Response($activeRequestHandler->getHttpResponse()); $this->dispatcher->dispatch($request, $response); return $response->getContent(); }
/** * Prepares the environment for and conducts an account authentication * * @param \TYPO3\Flow\Security\Account $account * @return void * @api */ protected function authenticateAccount(\TYPO3\Flow\Security\Account $account) { $this->testingProvider->setAuthenticationStatus(\TYPO3\Flow\Security\Authentication\TokenInterface::AUTHENTICATION_SUCCESSFUL); $this->testingProvider->setAccount($account); $this->securityContext->clearContext(); $requestHandler = self::$bootstrap->getActiveRequestHandler(); $httpRequest = $requestHandler->getHttpRequest(); $actionRequest = $this->router->route($httpRequest); $this->securityContext->setRequest($actionRequest); $this->authenticationManager->authenticate(); }
/** * @param Request $httpRequest * @return ActionRequest */ protected function route(Request $httpRequest) { $actionRequest = new ActionRequest($httpRequest); $matchResults = $this->router->route($httpRequest); if ($matchResults !== null) { $requestArguments = $actionRequest->getArguments(); $mergedArguments = Arrays::arrayMergeRecursiveOverrule($requestArguments, $matchResults); $actionRequest->setArguments($mergedArguments); } return $actionRequest; }
/** * Sends the given HTTP request * * @param \TYPO3\Flow\Http\Request $request * @return \TYPO3\Flow\Http\Response * @throws \TYPO3\Flow\Http\Exception * @api */ public function sendRequest(Request $request) { $requestHandler = $this->bootstrap->getActiveRequestHandler(); if (!$requestHandler instanceof \TYPO3\Flow\Tests\FunctionalTestRequestHandler) { throw new \TYPO3\Flow\Http\Exception('The browser\'s internal request engine has only been designed for use within functional tests.', 1335523749); } $response = new Response(); $requestHandler->setHttpRequest($request); $requestHandler->setHttpResponse($response); try { $actionRequest = $this->router->route($request); $this->securityContext->clearContext(); $this->securityContext->setRequest($actionRequest); $this->validatorResolver->reset(); $this->dispatcher->dispatch($actionRequest, $response); $session = $this->bootstrap->getObjectManager()->get('TYPO3\\Flow\\Session\\SessionInterface'); if ($session->isStarted()) { $session->close(); } } catch (\Exception $exception) { $pathPosition = strpos($exception->getFile(), 'Packages/'); $filePathAndName = $pathPosition !== FALSE ? substr($exception->getFile(), $pathPosition) : $exception->getFile(); $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : ''; $content = PHP_EOL . 'Uncaught Exception in Flow ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL; $content .= 'thrown in file ' . $filePathAndName . PHP_EOL; $content .= 'in line ' . $exception->getLine() . PHP_EOL . PHP_EOL; $content .= \TYPO3\Flow\Error\Debugger::getBacktraceCode($exception->getTrace(), FALSE, TRUE) . PHP_EOL; if ($exception instanceof \TYPO3\Flow\Exception) { $statusCode = $exception->getStatusCode(); } else { $statusCode = 500; } $response->setStatus($statusCode); $response->setContent($content); $response->setHeader('X-Flow-ExceptionCode', $exception->getCode()); $response->setHeader('X-Flow-ExceptionMessage', $exception->getMessage()); } return $response; }
/** * Handles a HTTP request * * @return void */ public function handleRequest() { // Create the request very early so the Resource Management has a chance to grab it: $this->request = Request::createFromEnvironment(); $this->response = new Response(); $this->boot(); $this->resolveDependencies(); $this->request->injectSettings($this->settings); $this->router->setRoutesConfiguration($this->routesConfiguration); $actionRequest = $this->router->route($this->request); $this->securityContext->setRequest($actionRequest); $this->dispatcher->dispatch($actionRequest, $this->response); $this->response->makeStandardsCompliant($this->request); $this->response->send(); $this->bootstrap->shutdown('Runtime'); $this->exit->__invoke(); }
/** * @test */ public function routeDoesNotStoresMatchResultsInCacheIfTheyAreNull() { $matchResults = NULL; $mockActionRequest = $this->getMockBuilder('TYPO3\\Flow\\Mvc\\ActionRequest')->disableOriginalConstructor()->getMock(); $mockHttpRequest = $this->getMockBuilder('TYPO3\\Flow\\Http\\Request')->disableOriginalConstructor()->getMock(); $mockHttpRequest->expects($this->once())->method('createActionRequest')->will($this->returnValue($mockActionRequest)); $mockRoute1 = $this->getMockBuilder('TYPO3\\Flow\\Mvc\\Routing\\Route')->getMock(); $mockRoute1->expects($this->once())->method('matches')->with($mockHttpRequest)->will($this->returnValue(FALSE)); $mockRoute2 = $this->getMockBuilder('TYPO3\\Flow\\Mvc\\Routing\\Route')->getMock(); $mockRoute2->expects($this->once())->method('matches')->with($mockHttpRequest)->will($this->returnValue(TRUE)); $mockRoute2->expects($this->once())->method('getMatchResults')->will($this->returnValue($matchResults)); $this->router->_set('routes', array($mockRoute1, $mockRoute2)); $mockRouterCachingService = $this->getMockBuilder('TYPO3\\Flow\\Mvc\\Routing\\RouterCachingService')->getMock(); $mockRouterCachingService->expects($this->once())->method('getCachedMatchResults')->with($mockHttpRequest)->will($this->returnValue(FALSE)); $mockRouterCachingService->expects($this->never())->method('storeMatchResults'); $this->router->_set('routerCachingService', $mockRouterCachingService); $this->router->route($mockHttpRequest); }
/** * Resolve a route for the request * * Stores the resolved route values in the ComponentContext to pass them * to other components. They can be accessed via ComponentContext::getParameter('TYPO3\Flow\Mvc\Routing\RoutingComponent', 'matchResults'); * * @param ComponentContext $componentContext * @return void */ public function handle(ComponentContext $componentContext) { $matchResults = $this->router->route($componentContext->getHttpRequest()); $componentContext->setParameter('TYPO3\\Flow\\Mvc\\Routing\\RoutingComponent', 'matchResults', $matchResults); }
/** * Resolve a route for the request * * Stores the resolved route values in the ComponentContext to pass them * to other components. They can be accessed via ComponentContext::getParameter(outingComponent::class, 'matchResults'); * * @param ComponentContext $componentContext * @return void */ public function handle(ComponentContext $componentContext) { $matchResults = $this->router->route($componentContext->getHttpRequest()); $componentContext->setParameter(RoutingComponent::class, 'matchResults', $matchResults); }