Symfony\Bundle\FrameworkBundle\Debug\TraceableEventDispatcher::addListener PHP Method

addListener() public method

{@inheritDoc}
public addListener ( $eventName, $listener, $priority )
    public function addListener($eventName, $listener, $priority = 0)
    {
        if (!is_callable($listener)) {
            if (is_string($listener)) {
                $typeDefinition = '[string] '.$listener;
            } elseif (is_array($listener)) {
                $typeDefinition = '[array] '.(is_object($listener[0]) ? get_class($listener[0]) : $listener[0]).'::'.$listener[1];
            } elseif (is_object($listener)) {
                $typeDefinition = '[object] '.get_class($listener);
            } else {
                $typeDefinition = '[?] '.var_export($listener, true);
            }

            throw new \RuntimeException(sprintf('The given callback (%s) for event "%s" is not callable.', $typeDefinition, $eventName));
        }

        parent::addListener($eventName, $listener, $priority);
    }

Usage Example

 public function testStaticCallable()
 {
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $dispatcher = new TraceableEventDispatcher($container);
     $dispatcher->addListener('onFooEvent', array(__NAMESPACE__ . '\\StaticClassFixture', 'staticListener'));
     $dispatcher->dispatch('onFooEvent');
     $this->assertTrue(StaticClassFixture::$called);
 }
All Usage Examples Of Symfony\Bundle\FrameworkBundle\Debug\TraceableEventDispatcher::addListener