vendor/sulu/sulu/src/Sulu/Bundle/WebsiteBundle/Routing/RequestListener.php line 43

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Bundle\WebsiteBundle\Routing;
  11. use Sulu\Component\Webspace\Analyzer\RequestAnalyzerInterface;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\HttpKernel\Event\RequestEvent;
  14. use Symfony\Component\HttpKernel\KernelEvents;
  15. use Symfony\Component\Routing\RouterInterface;
  16. class RequestListener implements EventSubscriberInterface
  17. {
  18.     /**
  19.      * @var RouterInterface
  20.      */
  21.     private $router;
  22.     /**
  23.      * @var RequestAnalyzerInterface
  24.      */
  25.     private $requestAnalyzer;
  26.     public function __construct(RouterInterface $routerRequestAnalyzerInterface $requestAnalyzer)
  27.     {
  28.         $this->router $router;
  29.         $this->requestAnalyzer $requestAnalyzer;
  30.     }
  31.     public static function getSubscribedEvents(): array
  32.     {
  33.         return [KernelEvents::REQUEST => ['onRequest'31]];
  34.     }
  35.     public function onRequest(RequestEvent $event)
  36.     {
  37.         $context $this->router->getContext();
  38.         $portalInformation $this->requestAnalyzer->getPortalInformation();
  39.         if ($portalInformation) {
  40.             if (!$context->hasParameter('prefix')) {
  41.                 $context->setParameter('prefix'$portalInformation->getPrefix());
  42.             }
  43.             if (!$context->hasParameter('host')) {
  44.                 $context->setParameter('host'$portalInformation->getHost());
  45.             }
  46.         }
  47.     }
  48. }