|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file has been created by developers from BitBag. |
| 5 | + * Feel free to contact us once you face any issues or want to start |
| 6 | + * You can find more information about us on https://bitbag.io and write us |
| 7 | + * an email on hello@bitbag.io. |
| 8 | + */ |
| 9 | + |
| 10 | +declare(strict_types=1); |
| 11 | + |
| 12 | +namespace BitBag\SyliusUserComPlugin\DependencyInjection; |
| 13 | + |
| 14 | +use BitBag\SyliusUserComPlugin\Security\Handler\LogoutEventAddHandler; |
| 15 | +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
| 16 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 17 | +use Symfony\Component\DependencyInjection\Definition; |
| 18 | +use Symfony\Component\DependencyInjection\Reference; |
| 19 | +use Symfony\Component\Security\Http\Event\LogoutEvent; |
| 20 | +use Webmozart\Assert\Assert; |
| 21 | + |
| 22 | +final class LogoutSubscriberPass implements CompilerPassInterface |
| 23 | +{ |
| 24 | + public function process(ContainerBuilder $container): void |
| 25 | + { |
| 26 | + if (!$container->hasParameter('sylius_shop.firewall_context_name')) { |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + $firewallName = $container->getParameter('sylius_shop.firewall_context_name'); |
| 31 | + Assert::string($firewallName); |
| 32 | + $securityDispatcherId = sprintf('security.event_dispatcher.%s', $firewallName); |
| 33 | + |
| 34 | + if (!$container->hasDefinition($securityDispatcherId)) { |
| 35 | + return; |
| 36 | + } |
| 37 | + |
| 38 | + $logoutListener = new Definition(LogoutEventAddHandler::class, [ |
| 39 | + new Reference('Spinbits\SyliusGoogleAnalytics4Plugin\Storage\EventsBag'), |
| 40 | + ]); |
| 41 | + |
| 42 | + $logoutListener->addTag('kernel.event_listener', [ |
| 43 | + 'event' => LogoutEvent::class, |
| 44 | + 'dispatcher' => $securityDispatcherId, |
| 45 | + 'method' => 'onLogout', |
| 46 | + ]); |
| 47 | + $logoutListener->setPublic(true); |
| 48 | + |
| 49 | + $container->setDefinition('bitbag.handler.user_logout_add_event', $logoutListener); |
| 50 | + } |
| 51 | +} |
0 commit comments