vendor/symfony/security/Http/RememberMe/ResponseListener.php line 27

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <[email protected]>
  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\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  13. use Symfony\Component\HttpKernel\KernelEvents;
  14. /**
  15.  * Adds remember-me cookies to the Response.
  16.  *
  17.  * @author Johannes M. Schmitt <[email protected]>
  18.  *
  19.  * @final since Symfony 4.3
  20.  */
  21. class ResponseListener implements EventSubscriberInterface
  22. {
  23.     public function onKernelResponse(FilterResponseEvent $event)
  24.     {
  25.         if (!$event->isMasterRequest()) {
  26.             return;
  27.         }
  28.         $request $event->getRequest();
  29.         $response $event->getResponse();
  30.         if ($request->attributes->has(RememberMeServicesInterface::COOKIE_ATTR_NAME)) {
  31.             $response->headers->setCookie($request->attributes->get(RememberMeServicesInterface::COOKIE_ATTR_NAME));
  32.         }
  33.     }
  34.     /**
  35.      * {@inheritdoc}
  36.      */
  37.     public static function getSubscribedEvents()
  38.     {
  39.         return [KernelEvents::RESPONSE => 'onKernelResponse'];
  40.     }
  41. }