vendor/symfony-cmf/seo-bundle/src/EventListener/LanguageListener.php line 32

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony CMF package.
  4.  *
  5.  * (c) 2011-2017 Symfony CMF
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Cmf\Bundle\SeoBundle\EventListener;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  13. use Symfony\Component\HttpKernel\KernelEvents;
  14. /**
  15.  * This listener adds a Content-Language header to the response.
  16.  *
  17.  * @author Wouter de Jong <wouter@wouterj.nl>
  18.  */
  19. class LanguageListener implements EventSubscriberInterface
  20. {
  21.     public static function getSubscribedEvents()
  22.     {
  23.         return [
  24.             KernelEvents::RESPONSE => 'onKernelResponse',
  25.         ];
  26.     }
  27.     public function onKernelResponse(FilterResponseEvent $event)
  28.     {
  29.         if ($event->getResponse()->headers->has('Content-Language')) {
  30.             return;
  31.         }
  32.         $locale $event->getRequest()->getLocale();
  33.         $language current(explode('_'$locale2));
  34.         $event->getResponse()->headers->set('Content-Language'$language);
  35.     }
  36. }