<?php

declare(strict_types=1);

namespace KupShop\UserOauthBundle\EventSubscriber;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Http\Event\LogoutEvent;

class LogoutSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            LogoutEvent::class => [
                ['onLogout', 200],
            ],
        ];
    }

    public function onLogout(LogoutEvent $event): void
    {
        // set `logout: true` session to notify js-shop
        $event->getRequest()->getSession()
            ->set('logout', true);
    }
}
