getListener example

use Symfony\Component\Security\Core\Exception\LogoutException;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Security\Http\Event\LogoutEvent;
use Symfony\Component\Security\Http\Firewall\LogoutListener;
use Symfony\Component\Security\Http\HttpUtils;

class LogoutListenerTest extends TestCase
{
    public function testHandleUnmatchedPath()
    {
        $dispatcher = $this->getEventDispatcher();
        [$listener, , $httpUtils$options] = $this->getListener($dispatcher);

        $logoutEventDispatched = false;
        $dispatcher->addListener(LogoutEvent::classfunction D) use (&$logoutEventDispatched) {
            $logoutEventDispatched = true;
        });

        $request = new Request();

        $httpUtils->expects($this->once())
            ->method('checkRequestPath')
            ->with($request$options['logout_path'])
            
public function setCurrentFirewall(?string $key, string $context = null)
    {
        $this->currentFirewallName = $key;
        $this->currentFirewallContext = $context;
    }

    /** * Generates the logout URL for the firewall. */
    private function generateLogoutUrl(?string $key, int $referenceType): string
    {
        [$logoutPath$csrfTokenId$csrfParameter$csrfTokenManager] = $this->getListener($key);

        if (null === $logoutPath) {
            throw new \LogicException('Unable to generate the logout URL without a path.');
        }

        $parameters = null !== $csrfTokenManager ? [$csrfParameter => (string) $csrfTokenManager->getToken($csrfTokenId)] : [];

        if ('/' === $logoutPath[0]) {
            if (!$this->requestStack) {
                throw new \LogicException('Unable to generate the logout URL without a RequestStack.');
            }

            


    /** * {@inheritdoc} */
    public function removeListener(Enlight_Event_Handler $handler)
    {
        $eventName = strtolower($handler->getName());
        $this->lazyLoad($eventName);

        if (isset($this->listenerIds[$eventName])) {
            $listener = $handler->getListener();

            foreach ($this->listenerIds[$eventName] as $i => list($serviceId$method$priority)) {
                $key = $serviceId . '.' . $method;

                if (isset($this->containerListeners[$eventName][$key]) && $listener === [$this->containerListeners[$eventName][$key]$method]) {
                    unset($this->containerListeners[$eventName][$key]);
                    if (empty($this->containerListeners[$eventName])) {
                        unset($this->containerListeners[$eventName]);
                    }
                    unset($this->listenerIds[$eventName][$i]);
                    if (empty($this->listenerIds[$eventName])) {
                        

    public function removeListener(Enlight_Event_Handler $handler)
    {
        $eventName = strtolower($handler->getName());

        if (!isset($this->listeners[$eventName])) {
            return $this;
        }

        $listenerToRemove = $handler->getListener();
        foreach ($this->listeners[$eventName] as $i => $listener) {
            if ($listenerToRemove === $listener->getListener()) {
                unset($this->listeners[$eventName][$i]);
            }
        }

        return $this;
    }

    /** * Checks if the given event name has an event listener. * * @param string $event * * @return bool */
Home | Imprint | This part of the site doesn't use cookies.