src/EventSubscriber/HostSubscriber.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  5. use Symfony\Component\HttpKernel\KernelEvents;
  6. /**
  7.  * Class HostSubscriber
  8.  * @package App\EventSubscriber
  9.  */
  10. class HostSubscriber implements EventSubscriberInterface
  11. {
  12.     public function __construct()
  13.     {
  14.     }
  15.     /**
  16.      * Host provenant du champ référence de l'entité App\Entity\Www\Sites
  17.      * @param RequestEvent $event
  18.      * @return void
  19.      */
  20.     public function onKernelRequestGetHost(RequestEvent $event)
  21.     {
  22.         $host $_SERVER["HTTP_HOST"];
  23.         $domainMappings = [
  24.             "abcm-refonte.local.atiweb.fr"    => "abcm",
  25.             "abcmzwei.eu"                     => "abcm",
  26.             "www.abcmzwei.eu"                 => "abcm",
  27.             "abcm-vitrine.atiweb.fr"          => "abcm",
  28.             "www.abcm-vitrine.atiweb.fr"      => "abcm",
  29.             "haguenau.abcm-vitrine.atiweb.fr" => "haguenau",
  30.             "abcm-haguenau.local.atiweb.fr"   => "haguenau",
  31.             "haguenau.abcmzwei.eu"            => "haguenau",
  32.         ];
  33.         define("WWW_HOST"$domainMappings[$host] ?? "");
  34.     }
  35.     /**
  36.      * @return array[]
  37.      */
  38.     public static function getSubscribedEvents()
  39.     {
  40.         return [
  41.             KernelEvents::REQUEST => ['onKernelRequestGetHost'0],
  42.         ];
  43.     }
  44. }