vendor/symfony/security-http/EventListener/RememberMeLogoutListener.php line 19

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\EventListener;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\Security\Core\Exception\LogicException;
  13. use Symfony\Component\Security\Http\Event\LogoutEvent;
  14. use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
  15. trigger_deprecation('symfony/security-http', '5.4', 'The "%s" class is deprecated.', RememberMeLogoutListener::class);
  16. /**
  17. * @author Wouter de Jong <wouter@wouterj.nl>
  18. *
  19. * @final
  20. *
  21. * @deprecated since Symfony 5.4
  22. */
  23. class RememberMeLogoutListener implements EventSubscriberInterface
  24. {
  25. private $rememberMeServices;
  26. public function __construct(RememberMeServicesInterface $rememberMeServices)
  27. {
  28. if (!method_exists($rememberMeServices, 'logout')) {
  29. trigger_deprecation('symfony/security-core', '5.1', '"%s" should implement the "logout(Request $request, Response $response, TokenInterface $token)" method, this method will be added to the "%s" in version 6.0.', \get_class($rememberMeServices), RememberMeServicesInterface::class);
  30. }
  31. $this->rememberMeServices = $rememberMeServices;
  32. }
  33. public function onLogout(LogoutEvent $event): void
  34. {
  35. if (!method_exists($this->rememberMeServices, 'logout')) {
  36. return;
  37. }
  38. if (!$event->getToken()) {
  39. return;
  40. }
  41. if (null === $event->getResponse()) {
  42. throw new LogicException(sprintf('No response was set for this logout action. Make sure the DefaultLogoutListener or another listener has set the response before "%s" is called.', __CLASS__));
  43. }
  44. $this->rememberMeServices->logout($event->getRequest(), $event->getResponse(), $event->getToken());
  45. }
  46. public static function getSubscribedEvents(): array
  47. {
  48. return [
  49. LogoutEvent::class => 'onLogout',
  50. ];
  51. }
  52. }