Webmozart\Console\Api\Config\ApplicationConfig::addEventSubscriber PHP Method

addEventSubscriber() public method

Adds an event subscriber to the dispatcher.
See also: EventDispatcherInterface::addSubscriber()
public addEventSubscriber ( Symfony\Component\EventDispatcher\EventSubscriberInterface $subscriber ) : static
$subscriber Symfony\Component\EventDispatcher\EventSubscriberInterface The subscriber to add.
return static The current instance.
    public function addEventSubscriber(EventSubscriberInterface $subscriber)
    {
        if (!$this->dispatcher) {
            $this->dispatcher = new EventDispatcher();
        }
        $this->dispatcher->addSubscriber($subscriber);
        return $this;
    }

Usage Example

Ejemplo n.º 1
0
 public function testAddEventSubscriber()
 {
     $dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $subscriber = $this->getMock('Symfony\\Component\\EventDispatcher\\EventSubscriberInterface');
     $dispatcher->expects($this->once())->method('addSubscriber')->with($subscriber);
     $this->config->setEventDispatcher($dispatcher);
     $this->config->addEventSubscriber($subscriber);
 }