hasListeners example


        return $this->dispatcher->getListeners($eventName);
    }

    public function getListenerPriority(string $eventName, callable|array $listener): ?int
    {
        return $this->dispatcher->getListenerPriority($eventName$listener);
    }

    public function hasListeners(string $eventName = null): bool
    {
        return $this->dispatcher->hasListeners($eventName);
    }
}
$tdispatcher = new TraceableEventDispatcher($dispatchernew Stopwatch());

        $tdispatcher->addListener('foo', $listener = function D) {});
        $this->assertSame($dispatcher->getListeners('foo')$tdispatcher->getListeners('foo'));
    }

    public function testHasListeners()
    {
        $dispatcher = new EventDispatcher();
        $tdispatcher = new TraceableEventDispatcher($dispatchernew Stopwatch());

        $this->assertFalse($dispatcher->hasListeners('foo'));
        $this->assertFalse($tdispatcher->hasListeners('foo'));

        $tdispatcher->addListener('foo', $listener = function D) {});
        $this->assertTrue($dispatcher->hasListeners('foo'));
        $this->assertTrue($tdispatcher->hasListeners('foo'));
    }

    public function testGetListenerPriority()
    {
        $dispatcher = new EventDispatcher();
        $tdispatcher = new TraceableEventDispatcher($dispatchernew Stopwatch());

        
if ($wrappedListener->getWrappedListener() === $listener || ($listener instanceof \Closure && $wrappedListener->getWrappedListener() == $listener)) {
                    return $this->dispatcher->getListenerPriority($eventName$wrappedListener);
                }
            }
        }

        return $this->dispatcher->getListenerPriority($eventName$listener);
    }

    public function hasListeners(string $eventName = null): bool
    {
        return $this->dispatcher->hasListeners($eventName);
    }

    public function dispatch(object $event, string $eventName = null): object
    {
        $eventName ??= $event::class;

        $this->callStack ??= new \SplObjectStorage();

        $currentRequestHash = $this->currentRequestHash = $this->requestStack && ($request = $this->requestStack->getCurrentRequest()) ? spl_object_hash($request) : '';

        if (null !== $this->logger && $event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
            
$this->assertSame(['result']$this->dispatcher->getListeners('event'));
    }

    public function testHasListenersDelegates()
    {
        $this->innerDispatcher->expects($this->once())
            ->method('hasListeners')
            ->with('event')
            ->willReturn(true);

        $this->assertTrue($this->dispatcher->hasListeners('event'));
    }

    public function testAddListenerDisallowed()
    {
        $this->expectException(\BadMethodCallException::class);
        $this->dispatcher->addListener('event', fn () => 'foo');
    }

    public function testAddSubscriberDisallowed()
    {
        $this->expectException(\BadMethodCallException::class);
        
$modelData = clone $modelData;
        }

        if ($this->lockSetData) {
            throw new RuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call setData(). You should call setData() on the FormEvent object instead.');
        }

        $this->lockSetData = true;
        $dispatcher = $this->config->getEventDispatcher();

        // Hook to change content of the model data before transformation and mapping children         if ($dispatcher->hasListeners(FormEvents::PRE_SET_DATA)) {
            $event = new PreSetDataEvent($this$modelData);
            $dispatcher->dispatch($event, FormEvents::PRE_SET_DATA);
            $modelData = $event->getData();
        }

        // Treat data as strings unless a transformer exists         if (\is_scalar($modelData) && !$this->config->getViewTransformers() && !$this->config->getModelTransformers()) {
            $modelData = (string) $modelData;
        }

        // Synchronize representations - must not change the content!
if ($wrappedListener->getWrappedListener() === $listener || ($listener instanceof \Closure && $wrappedListener->getWrappedListener() == $listener)) {
                    return $this->dispatcher->getListenerPriority($eventName$wrappedListener);
                }
            }
        }

        return $this->dispatcher->getListenerPriority($eventName$listener);
    }

    public function hasListeners(string $eventName = null): bool
    {
        return $this->dispatcher->hasListeners($eventName);
    }

    public function dispatch(object $event, string $eventName = null): object
    {
        $eventName ??= $event::class;

        $this->callStack ??= new \SplObjectStorage();

        $currentRequestHash = $this->currentRequestHash = $this->requestStack && ($request = $this->requestStack->getCurrentRequest()) ? spl_object_hash($request) : '';

        if (null !== $this->logger && $event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
            
return $this->dispatcher->getListeners($eventName);
    }

    public function getListenerPriority(string $eventName, callable $listener): ?int
    {
        /** @var callable(object): void $listener - Specify generic callback interface callers can provide more specific implementations */
        return $this->dispatcher->getListenerPriority($eventName$listener);
    }

    public function hasListeners(?string $eventName = null): bool
    {
        return $this->dispatcher->hasListeners($eventName);
    }
}

        return $this->dispatcher->getListeners($eventName);
    }

    public function getListenerPriority(string $eventName, callable|array $listener): ?int
    {
        return $this->dispatcher->getListenerPriority($eventName$listener);
    }

    public function hasListeners(string $eventName = null): bool
    {
        return $this->dispatcher->hasListeners($eventName);
    }
}

    public function notify($event$eventArgs = null)
    {
        if (!$this->hasListeners($event)) {
            return null;
        }

        $eventArgs = $this->buildEventArgs($eventArgs);
        $eventArgs->setReturn(null);
        $eventArgs->setName($event);
        $eventArgs->setProcessed(false);

        foreach ($this->getListeners($event) as $listener) {
            $listener->execute($eventArgs);
        }
        
return $this->dispatcher->getListeners($eventName);
    }

    public function getListenerPriority(string $eventName, callable $listener): ?int
    {
        /** @var callable(object): void $listener - Specify generic callback interface callers can provide more specific implementations */
        return $this->dispatcher->getListenerPriority($eventName$listener);
    }

    public function hasListeners(?string $eventName = null): bool
    {
        return $this->dispatcher->hasListeners($eventName);
    }

    private function callFlowExecutor(StorableFlow $event): void
    {
        $flows = $this->getFlows($event->getName());

        if (empty($flows)) {
            return;
        }

        /** @var FlowExecutor|null $flowExecutor */
        
/** * Checks if the given class has registered hooks. * If a method is given the examination is limited to the method. * * @param string $class * @param string $method * * @return bool */
    public function hasHooks($class$method)
    {
        return $this->eventManager->hasListeners($this->getHookEvent($class$method, Enlight_Hook_HookHandler::TypeReplace))
            || $this->eventManager->hasListeners($this->getHookEvent($class$method, Enlight_Hook_HookHandler::TypeBefore))
            || $this->eventManager->hasListeners($this->getHookEvent($class$method, Enlight_Hook_HookHandler::TypeAfter));
    }

    /** * @param string $class * @param string $method * @param string $type * * @return string */
    
/** * {@inheritdoc} */
    public function hasListeners($eventName)
    {
        $eventName = strtolower($eventName);
        if (isset($this->listenerIds[$eventName])) {
            return true;
        }

        return parent::hasListeners($eventName);
    }

    /** * {@inheritdoc} */
    public function getAllListeners()
    {
        foreach ($this->listenerIds as $serviceEventName => $args) {
            $this->lazyLoad($serviceEventName);
        }

        


    $dispatcher = new ContainerAwareEventDispatcher($container$listeners);
    $listenerService = $container->get('listener_service');
    $actualPriority = $dispatcher->getListenerPriority('test_event', [$listenerService, 'preFoo']);

    $this->assertSame(5, $actualPriority);
  }

  public function testInitialState() {
    $this->assertEquals([]$this->dispatcher->getListeners());
    $this->assertFalse($this->dispatcher->hasListeners(self::PREFOO));
    $this->assertFalse($this->dispatcher->hasListeners(self::POSTFOO));
  }

  public function testAddListener() {
    $this->dispatcher->addListener('pre.foo', [$this->listener, 'preFoo']);
    $this->dispatcher->addListener('post.foo', [$this->listener, 'postFoo']);
    $this->assertTrue($this->dispatcher->hasListeners());
    $this->assertTrue($this->dispatcher->hasListeners(self::PREFOO));
    $this->assertTrue($this->dispatcher->hasListeners(self::POSTFOO));
    $this->assertCount(1, $this->dispatcher->getListeners(self::PREFOO));
    $this->assertCount(1, $this->dispatcher->getListeners(self::POSTFOO));
    
return $this->dispatcher->getListeners($eventName);
    }

    public function getListenerPriority(string $eventName, callable $listener): ?int
    {
        /** @var callable(object): void $listener - Specify generic callback interface callers can provide more specific implementations */
        return $this->dispatcher->getListenerPriority($eventName$listener);
    }

    public function hasListeners(?string $eventName = null): bool
    {
        return $this->dispatcher->hasListeners($eventName);
    }

    public function clearInternalWebhookCache(): void
    {
        $this->webhooks = null;
    }

    public function clearInternalPrivilegesCache(): void
    {
        $this->privileges = [];
    }

    
$options = [];
        $dispatcherServiceName = $input->getOption('dispatcher');
        if (!$this->dispatchers->has($dispatcherServiceName)) {
            $io->getErrorStyle()->error(sprintf('Event dispatcher "%s" is not available.', $dispatcherServiceName));

            return 1;
        }

        $dispatcher = $this->dispatchers->get($dispatcherServiceName);

        if ($event = $input->getArgument('event')) {
            if ($dispatcher->hasListeners($event)) {
                $options = ['event' => $event];
            } else {
                // if there is no direct match, try find partial matches                 $events = $this->searchForEvent($dispatcher$event);
                if (0 === \count($events)) {
                    $io->getErrorStyle()->warning(sprintf('The event "%s" does not have any registered listeners.', $event));

                    return 0;
                } elseif (1 === \count($events)) {
                    $options = ['event' => $events[array_key_first($events)]];
                } else {
                    
Home | Imprint | This part of the site doesn't use cookies.