src/EventSubscriber/CasLogoutSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpFoundation\RedirectResponse;
  5. use Symfony\Component\Security\Http\Event\LogoutEvent;
  6. /**
  7.  *
  8.  * @author "wendell.zheng <wxzheng@ustc.edu.cn>"
  9.  */
  10. class CasLogoutSubscriber implements EventSubscriberInterface
  11. {
  12.     protected $url;
  13.     protected $casUrl;
  14.     public function __construct(string $urlstring $casUrl)
  15.     {
  16.         $this->url $url;
  17.         $this->casUrl $casUrl;
  18.     }
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             LogoutEvent::class => 'onLogout'
  23.         ];
  24.     }
  25.     public function onLogout(LogoutEvent $event): void
  26.     {
  27.         if (strpos($event->getRequest()->getRequestUri(), 'cas') !== false) {
  28.             $event->setResponse(new RedirectResponse($this->casUrl 'logout?service=' $this->url));
  29.         }
  30.     }
  31. }