src/EventListener/ResponseListener.php line 33

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of the Pimcore X Installation by
  4.  * ercas GmbH & CO. KG <https://www.ercasdieagentur.de>
  5.  *
  6.  *  @license GPLv3
  7.  */
  8. namespace App\EventListener;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  11. use Symfony\Component\HttpKernel\KernelEvents;
  12. /**
  13.  * Adds remember-me cookies to the Response.
  14.  *
  15.  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  16.  *
  17.  * @final
  18.  */
  19. class ResponseListener implements EventSubscriberInterface
  20. {
  21.     /**
  22.      * This attribute name can be used by the implementation if it needs to set
  23.      * a cookie on the Request when there is no actual Response, yet.
  24.      */
  25.     public const COOKIE_AFTER_NAME '_security_remember_me_cookie';
  26.     public const COOKIE_BEFORE_NAME 'REMEMBERME';
  27.     public function onKernelResponse(ResponseEvent $event)
  28.     {
  29.         if (!$event->isMainRequest()) {
  30.             return;
  31.         }
  32.         $request $event->getRequest();
  33.         $response $event->getResponse();
  34.         if ($request->cookies->get(self::COOKIE_BEFORE_NAME)) {
  35.             if(!$request->cookies->get(self::COOKIE_AFTER_NAME)) {
  36.                 /*  setcookie(
  37.                     self::COOKIE_AFTER_NAME,
  38.                     $request->cookies->get(self::COOKIE_BEFORE_NAME),
  39.                     time()+36000, //10 hours
  40.                     '',
  41.                     '',
  42.                     true,
  43.                     false
  44.                 );  */
  45.             }
  46.             //check if already exist // delete REMEMBERME
  47.         }
  48.     }
  49.     /**
  50.      * {@inheritdoc}
  51.      */
  52.     public static function getSubscribedEvents(): array
  53.     {
  54.         return [KernelEvents::RESPONSE => 'onKernelResponse'];
  55.     }
  56. }