/**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * Create an action request from stored route match values and dispatch to that
  *
  * @param ComponentContext $componentContext
  * @return void
  */
 public function handle(ComponentContext $componentContext)
 {
     $httpRequest = $componentContext->getHttpRequest();
     /** @var $actionRequest ActionRequest */
     $actionRequest = $this->objectManager->get(ActionRequest::class, $httpRequest);
     $this->securityContext->setRequest($actionRequest);
     $routingMatchResults = $componentContext->getParameter(Routing\RoutingComponent::class, 'matchResults');
     $actionRequest->setArguments($this->mergeArguments($httpRequest, $routingMatchResults));
     $this->setDefaultControllerAndActionNameIfNoneSpecified($actionRequest);
     $componentContext->setParameter(self::class, 'actionRequest', $actionRequest);
     $this->dispatcher->dispatch($actionRequest, $componentContext->getHttpResponse());
 }
 /**
  * Check if the current request contains a widget context.
  * If so dispatch it directly, otherwise continue with the next HTTP component.
  *
  * @param ComponentContext $componentContext
  * @return void
  * @throws ComponentException
  */
 public function handle(ComponentContext $componentContext)
 {
     $httpRequest = $componentContext->getHttpRequest();
     $widgetContext = $this->extractWidgetContext($httpRequest);
     if ($widgetContext === null) {
         return;
     }
     /** @var $actionRequest ActionRequest */
     $actionRequest = $this->objectManager->get(\TYPO3\Flow\Mvc\ActionRequest::class, $httpRequest);
     $actionRequest->setArguments($this->mergeArguments($httpRequest, array()));
     $actionRequest->setArgument('__widgetContext', $widgetContext);
     $actionRequest->setControllerObjectName($widgetContext->getControllerObjectName());
     $this->setDefaultControllerAndActionNameIfNoneSpecified($actionRequest);
     $this->securityContext->setRequest($actionRequest);
     $this->dispatcher->dispatch($actionRequest, $componentContext->getHttpResponse());
     // stop processing the current component chain
     $componentContext->setParameter(\TYPO3\Flow\Http\Component\ComponentChain::class, 'cancel', true);
 }
 /**
  * @param ComponentContext $componentContext
  * @return void
  * @throws FileNotFoundException|AccessDeniedException|FlowException
  */
 public function handle(ComponentContext $componentContext)
 {
     $httpRequest = $componentContext->getHttpRequest();
     if (!$httpRequest->hasArgument('__protectedResource')) {
         return;
     }
     try {
         $encodedResourceData = $this->hashService->validateAndStripHmac($httpRequest->getArgument('__protectedResource'));
     } catch (InvalidHashException $exception) {
         throw new AccessDeniedException('Invalid HMAC!', 1421241393, $exception);
     }
     $tokenData = json_decode(base64_decode($encodedResourceData), TRUE);
     $this->verifyExpiration($tokenData);
     $this->verifySecurityContextHash($tokenData, $httpRequest);
     $resource = $this->resourceManager->getResourceBySha1($tokenData['resourceIdentifier']);
     if ($resource === NULL) {
         throw new FileNotFoundException(sprintf('Unknown resource!%sCould not find resource with identifier "%s"', chr(10), $tokenData['resourceIdentifier']), 1429621743);
     }
     // TODO there should be a better way to determine the absolute path of the resource? Resource::createTemporaryLocalCopy() is too expensive
     $resourcePathAndFilename = Files::concatenatePaths(array($this->options['basePath'], $tokenData['resourceIdentifier'][0], $tokenData['resourceIdentifier'][1], $tokenData['resourceIdentifier'][2], $tokenData['resourceIdentifier'][3], $tokenData['resourceIdentifier']));
     if (!is_file($resourcePathAndFilename)) {
         throw new FileNotFoundException(sprintf('File not found!%sThe file "%s" does not exist', chr(10), $resourcePathAndFilename), 1429702284);
     }
     if (!isset($this->options['serveStrategy'])) {
         throw new FlowException('No "serveStrategy" configured!', 1429704107);
     }
     $fileServeStrategy = $this->objectManager->get($this->options['serveStrategy']);
     if (!$fileServeStrategy instanceof FileServeStrategyInterface) {
         throw new FlowException(sprintf('The class "%s" does not implement the FileServeStrategyInterface', get_class($fileServeStrategy)), 1429704284);
     }
     $httpResponse = $componentContext->getHttpResponse();
     $httpResponse->setHeader('Content-Type', $resource->getMediaType());
     $this->emitResourceServed($resource, $httpRequest);
     $fileServeStrategy->serve($resourcePathAndFilename, $httpResponse);
     $componentContext->setParameter('TYPO3\\Flow\\Http\\Component\\ComponentChain', 'cancel', TRUE);
 }
 /**
  * @test
  */
 public function setParameterStoresTheGivenParameter()
 {
     $this->componentContext->setParameter('Some\\Component\\ClassName', 'someParameter', 'someParameterValue');
     $this->assertSame('someParameterValue', $this->componentContext->getParameter('Some\\Component\\ClassName', 'someParameter'));
 }
 /**
  * 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);
 }
 /**
  * Sends the given HTTP request
  *
  * @param Http\Request $httpRequest
  * @return Http\Response
  * @throws Http\Exception
  * @api
  */
 public function sendRequest(Http\Request $httpRequest)
 {
     $requestHandler = $this->bootstrap->getActiveRequestHandler();
     if (!$requestHandler instanceof FunctionalTestRequestHandler) {
         throw new Http\Exception('The browser\'s internal request engine has only been designed for use within functional tests.', 1335523749);
     }
     $this->securityContext->clearContext();
     $this->validatorResolver->reset();
     $response = new Http\Response();
     $requestHandler->setHttpRequest($httpRequest);
     $requestHandler->setHttpResponse($response);
     $objectManager = $this->bootstrap->getObjectManager();
     $baseComponentChain = $objectManager->get('TYPO3\\Flow\\Http\\Component\\ComponentChain');
     $componentContext = new ComponentContext($httpRequest, $response);
     $componentContext->setParameter('TYPO3\\Flow\\Mvc\\Routing\\RoutingComponent', 'skipRouterInitialization', TRUE);
     try {
         $baseComponentChain->handle($componentContext);
     } 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 .= Debugger::getBacktraceCode($exception->getTrace(), FALSE, TRUE) . PHP_EOL;
         if ($exception instanceof 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());
     }
     $session = $this->bootstrap->getObjectManager()->get('TYPO3\\Flow\\Session\\SessionInterface');
     if ($session->isStarted()) {
         $session->close();
     }
     return $response;
 }
 /**
  * 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);
 }
 /**
  * @param ComponentContext $componentContext
  * @return void
  */
 public function handle(ComponentContext $componentContext)
 {
     $httpRequest = $componentContext->getHttpRequest();
     $requestPath = $httpRequest->getUri()->getPath();
     $firstRequestPathSegment = explode('/', ltrim($requestPath, '/'))[0];
     //Check if url contains user, if so, don't detect language
     if (strpos($requestPath, '@user-')) {
         return;
     }
     if (isset($this->options['allowedMethods']) && !in_array($httpRequest->getMethod(), $this->options['allowedMethods'])) {
         //the current HTTP method is not within the allow methods, abort!
         return;
     }
     $preset = null;
     if (!isset($this->options['ignoreSegments']) || !in_array($firstRequestPathSegment, $this->options['ignoreSegments'])) {
         $preset = $this->findPreset($firstRequestPathSegment);
         if ($preset !== null) {
             //uri contains a valid language segment => no need for us to proceed
             return;
         }
     } else {
         //the configuration told us to ignore this segment => no need for us to proceed
         return;
     }
     $defaultPreset = $this->contentDimensionPresetSource->getDefaultPreset('language');
     $referer = $httpRequest->getHeaders()->get('Referer');
     $refererInfo = $this->parseUriInfo($referer);
     $currentInfo = $this->parseUriInfo((string) $httpRequest->getUri());
     $varnishInfo = isset($this->varnishSettings['varnishUrl']) ? $this->parseUriInfo($this->varnishSettings['varnishUrl']) : null;
     if ($refererInfo['host'] == $currentInfo['host'] || $varnishInfo !== null && $refererInfo['host'] == $varnishInfo['host']) {
         $firstRefererRequestPathSegment = explode('/', ltrim($refererInfo['requestPath'], '/'))[0];
         $refererPreset = $preset = $this->findPreset($firstRefererRequestPathSegment);
         if (empty($firstRequestPathSegment) && $refererPreset !== null && empty(ltrim(str_replace($firstRefererRequestPathSegment, '', $refererInfo['requestPath']), '/'))) {
             $preset = $defaultPreset;
         } else {
             $preset = $refererPreset;
         }
     } else {
         $detectedLocale = $this->localeDetector->detectLocaleFromHttpHeader($httpRequest->getHeader('Accept-Language'));
         if ($detectedLocale instanceof Locale) {
             $preset = $this->findPreset($detectedLocale->getLanguage());
             if ($preset !== null && empty(trim($requestPath, " \t\n\r\v/")) && $preset['uriSegment'] == $defaultPreset['uriSegment']) {
                 //we're on the homepage, and the browsers language is equal to the default language => no need for us to proceed
                 return;
             }
         }
     }
     if ($preset === null) {
         $preset = $defaultPreset;
     }
     if ($preset === null) {
         throw new Exception("Couldn't resolve the language and default language is not set. Check your language config.");
         return;
     }
     $uri = $httpRequest->getUri();
     if (isset($this->httpSettings['baseUri'])) {
         $baseInfo = $this->parseUriInfo($this->httpSettings['baseUri']);
         $uri->setHost($baseInfo['host']);
     }
     if (isset($this->httpSettings['port'])) {
         $uri->setPort($this->httpSettings['port']);
     }
     if (isset($this->httpSettings['username'])) {
         $uri->setUsername($this->httpSettings['username']);
     }
     if (isset($this->httpSettings['password'])) {
         $uri->setUsername($this->httpSettings['password']);
     }
     $uri->setPath('/' . $preset['uriSegment'] . $requestPath);
     $response = $componentContext->getHttpResponse();
     $response->setContent(sprintf('<html><head><meta http-equiv="refresh" content="0;url=%s"/></head></html>', htmlentities((string) $uri, ENT_QUOTES, 'utf-8')));
     $response->setHeader('Location', (string) $uri);
     $componentContext->setParameter(ComponentChain::class, 'cancel', TRUE);
 }