vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/ResponseListener.php line 35

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  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\Component\HttpKernel\EventListener;
  11. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  12. use Symfony\Component\HttpKernel\KernelEvents;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. /**
  15.  * ResponseListener fixes the Response headers based on the Request.
  16.  *
  17.  * @author Fabien Potencier <fabien@symfony.com>
  18.  */
  19. class ResponseListener implements EventSubscriberInterface
  20. {
  21.     private $charset;
  22.     public function __construct($charset)
  23.     {
  24.         $this->charset $charset;
  25.     }
  26.     /**
  27.      * Filters the Response.
  28.      */
  29.     public function onKernelResponse(FilterResponseEvent $event)
  30.     {
  31.         if (!$event->isMasterRequest()) {
  32.             return;
  33.         }
  34.         $response $event->getResponse();
  35.         if (null === $response->getCharset()) {
  36.             $response->setCharset($this->charset);
  37.         }
  38.         $response->prepare($event->getRequest());
  39.     }
  40.     public static function getSubscribedEvents()
  41.     {
  42.         return array(
  43.             KernelEvents::RESPONSE => 'onKernelResponse',
  44.         );
  45.     }
  46. }