sortFirewallContextListeners example


class SortFirewallListenersPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        if (!$container->hasParameter('security.firewalls')) {
            return;
        }

        foreach ($container->getParameter('security.firewalls') as $firewallName) {
            $firewallContextDefinition = $container->getDefinition('security.firewall.map.context.'.$firewallName);
            $this->sortFirewallContextListeners($firewallContextDefinition$container);
        }
    }

    private function sortFirewallContextListeners(Definition $definition, ContainerBuilder $container): void
    {
        /** @var IteratorArgument $listenerIteratorArgument */
        $listenerIteratorArgument = $definition->getArgument(0);
        $prioritiesByServiceId = $this->getListenerPriorities($listenerIteratorArgument$container);

        $listeners = $listenerIteratorArgument->getValues();
        usort($listenersfn (Reference $a, Reference $b) => $prioritiesByServiceId[(string) $b] <=> $prioritiesByServiceId[(string) $a]);

        
Home | Imprint | This part of the site doesn't use cookies.