vendor/symfony/symfony/src/Symfony/Component/Security/Http/RememberMe/ResponseListener.php line 25

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\Security\Http\RememberMe;
  11. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  12. use Symfony\Component\HttpKernel\KernelEvents;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. /**
  15.  * Adds remember-me cookies to the Response.
  16.  *
  17.  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  18.  */
  19. class ResponseListener implements EventSubscriberInterface
  20. {
  21.     public function onKernelResponse(FilterResponseEvent $event)
  22.     {
  23.         if (!$event->isMasterRequest()) {
  24.             return;
  25.         }
  26.         $request $event->getRequest();
  27.         $response $event->getResponse();
  28.         if ($request->attributes->has(RememberMeServicesInterface::COOKIE_ATTR_NAME)) {
  29.             $response->headers->setCookie($request->attributes->get(RememberMeServicesInterface::COOKIE_ATTR_NAME));
  30.         }
  31.     }
  32.     /**
  33.      * {@inheritdoc}
  34.      */
  35.     public static function getSubscribedEvents()
  36.     {
  37.         return array(KernelEvents::RESPONSE => 'onKernelResponse');
  38.     }
  39. }