/**
  * Set the routes configuration for the Neos setup and configures the routing component
  * to skip initialisation, which would overwrite the specific settings again.
  *
  * @param ComponentContext $componentContext
  * @return void
  */
 public function handle(ComponentContext $componentContext)
 {
     $configurationSource = $this->objectManager->get('TYPO3\\Flow\\Configuration\\Source\\YamlSource');
     $routesConfiguration = $configurationSource->load($this->packageManager->getPackage('TYPO3.Setup')->getConfigurationPath() . ConfigurationManager::CONFIGURATION_TYPE_ROUTES);
     $this->router->setRoutesConfiguration($routesConfiguration);
     $componentContext->setParameter('TYPO3\\Flow\\Mvc\\Routing\\RoutingComponent', 'skipRouterInitialization', TRUE);
 }
 /**
  * @test
  */
 public function handleStoresRouterMatchResultsInTheComponentContext()
 {
     $mockMatchResults = array('someRouterMatchResults');
     $this->mockRouter->expects($this->atLeastOnce())->method('route')->with($this->mockHttpRequest)->will($this->returnValue($mockMatchResults));
     $this->mockComponentContext->expects($this->atLeastOnce())->method('setParameter')->with(\TYPO3\Flow\Mvc\Routing\RoutingComponent::class, 'matchResults', $mockMatchResults);
     $this->routingComponent->handle($this->mockComponentContext);
 }
 /**
  * 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();
 }
 /**
  * Route the given route path
  *
  * This command takes a given path and displays the detected route and
  * the selected package, controller and action.
  *
  * @param string $path The route path to resolve
  * @param string $method The request method (GET, POST, PUT, DELETE, ...) to simulate
  * @return void
  */
 public function routePathCommand($path, $method = 'GET')
 {
     $server = array('REQUEST_URI' => $path, 'REQUEST_METHOD' => $method);
     $httpRequest = new Request(array(), array(), array(), $server);
     /** @var Route $route */
     foreach ($this->router->getRoutes() as $route) {
         if ($route->matches($httpRequest) === true) {
             $routeValues = $route->getMatchResults();
             $this->outputLine('<b>Path:</b>');
             $this->outputLine('  ' . $path);
             $this->outputLine('<b>Route:</b>');
             $this->outputLine('  Name: ' . $route->getName());
             $this->outputLine('  Pattern: ' . $route->getUriPattern());
             $this->outputLine('<b>Result:</b>');
             $this->outputLine('  Package: ' . (isset($routeValues['@package']) ? $routeValues['@package'] : '-'));
             $this->outputLine('  Subpackage: ' . (isset($routeValues['@subpackage']) ? $routeValues['@subpackage'] : '-'));
             $this->outputLine('  Controller: ' . (isset($routeValues['@controller']) ? $routeValues['@controller'] : '-'));
             $this->outputLine('  Action: ' . (isset($routeValues['@action']) ? $routeValues['@action'] : '-'));
             $this->outputLine('  Format: ' . (isset($routeValues['@format']) ? $routeValues['@format'] : '-'));
             $controllerObjectName = $this->getControllerObjectName($routeValues['@package'], isset($routeValues['@subpackage']) ? $routeValues['@subpackage'] : null, $routeValues['@controller']);
             if ($controllerObjectName === null) {
                 $this->outputLine('<b>Controller Error:</b>');
                 $this->outputLine('  !!! No Controller Object found !!!');
                 $this->quit(1);
             }
             $this->outputLine('<b>Controller:</b>');
             $this->outputLine('  ' . $controllerObjectName);
             $this->quit(0);
         }
     }
     $this->outputLine('No matching Route was found');
     $this->quit(1);
 }
 /**
  * Adds a route that can be used in the functional tests
  *
  * @param string $name Name of the route
  * @param string $uriPattern The uriPattern property of the route
  * @param array $defaults An array of defaults declarations
  * @param boolean $appendExceedingArguments If exceeding arguments may be appended
  * @return void
  * @api
  */
 protected function registerRoute($name, $uriPattern, array $defaults, $appendExceedingArguments = FALSE)
 {
     $route = new Route();
     $route->setName($name);
     $route->setUriPattern($uriPattern);
     $route->setDefaults($defaults);
     $route->setAppendExceedingArguments($appendExceedingArguments);
     $this->router->addRoute($route);
 }
示例#7
0
 /**
  * @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();
 }
示例#8
0
 /**
  * @return \TYPO3\Flow\Mvc\Routing\Router
  */
 protected function getRouter()
 {
     if ($this->router === NULL) {
         $this->router = $this->objectManager->get('\\TYPO3\\Flow\\Mvc\\Routing\\Router');
         $configurationManager = $this->objectManager->get('TYPO3\\Flow\\Configuration\\ConfigurationManager');
         $routesConfiguration = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_ROUTES);
         $this->router->setRoutesConfiguration($routesConfiguration);
     }
     return $this->router;
 }
示例#9
0
 /**
  * @test
  */
 public function findMatchResultsSetsLastMatchedRoute()
 {
     $mockHttpRequest = $this->getMockBuilder('TYPO3\\Flow\\Http\\Request')->disableOriginalConstructor()->getMock();
     $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));
     $this->router->_set('routes', array($mockRoute1, $mockRoute2));
     $this->router->_call('findMatchResults', $mockHttpRequest);
     $this->assertSame($mockRoute2, $this->router->getLastMatchedRoute());
 }
 /**
  * Adds a route that can be used in the functional tests
  *
  * @param string $name Name of the route
  * @param string $uriPattern The uriPattern property of the route
  * @param array $defaults An array of defaults declarations
  * @param boolean $appendExceedingArguments If exceeding arguments may be appended
  * @param array $httpMethods An array of accepted http methods
  * @return void
  * @api
  */
 protected function registerRoute($name, $uriPattern, array $defaults, $appendExceedingArguments = false, array $httpMethods = null)
 {
     $route = new Route();
     $route->setName($name);
     $route->setUriPattern($uriPattern);
     $route->setDefaults($defaults);
     $route->setAppendExceedingArguments($appendExceedingArguments);
     if ($httpMethods !== null) {
         $route->setHttpMethods($httpMethods);
     }
     $this->router->addRoute($route);
 }
 /**
  * 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;
 }
 /**
  * @param string $defaultPackageKey
  * @return StandaloneView
  */
 protected function createStandaloneView($defaultPackageKey = null)
 {
     // initialize router
     $this->router->setRoutesConfiguration($this->routesConfiguration);
     // initialize view
     $standaloneView = new StandaloneView();
     $actionRequest = $standaloneView->getRequest();
     // inject TYPO3.Flow settings to fetch base URI configuration & set default package key
     if (isset($this->flowSettings['http']['baseUri'])) {
         $actionRequest->getHttpRequest()->setBaseUri($this->flowSettings['http']['baseUri']);
     }
     $actionRequest->setControllerPackageKey($defaultPackageKey);
     return $standaloneView;
 }
示例#13
0
 /**
  * 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();
 }
 /**
  * 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);
 }
 /**
  * @test
  */
 public function getLastMatchedRouteReturnsNullByDefault()
 {
     $this->assertNull($this->router->getLastMatchedRoute());
 }
 /**
  * Initialize this engine
  *
  * @return void
  */
 public function initializeObject()
 {
     $this->router->setRoutesConfiguration($this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_ROUTES));
 }
 /**
  * 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);
 }