vendor/symfony/security-http/RememberMe/ResponseListener.php line 33

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\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  13. use Symfony\Component\HttpKernel\KernelEvents;
  14. /**
  15. * Adds remember-me cookies to the Response.
  16. *
  17. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  18. *
  19. * @final
  20. */
  21. class ResponseListener implements EventSubscriberInterface
  22. {
  23. /**
  24. * This attribute name can be used by the implementation if it needs to set
  25. * a cookie on the Request when there is no actual Response, yet.
  26. */
  27. public const COOKIE_ATTR_NAME = '_security_remember_me_cookie';
  28. public function onKernelResponse(ResponseEvent $event)
  29. {
  30. if (!$event->isMainRequest()) {
  31. return;
  32. }
  33. $request = $event->getRequest();
  34. $response = $event->getResponse();
  35. if ($request->attributes->has(self::COOKIE_ATTR_NAME)) {
  36. $response->headers->setCookie($request->attributes->get(self::COOKIE_ATTR_NAME));
  37. }
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public static function getSubscribedEvents(): array
  43. {
  44. return [KernelEvents::RESPONSE => 'onKernelResponse'];
  45. }
  46. }