public function addListenerService($eventName, $callback, $priority = 0)
 {
     if (!is_array($callback) || 2 !== count($callback)) {
         throw new \InvalidArgumentException('Expected an array("service", "method") argument');
     }
     $bundle = $this->kernel->getBundleByServiceId($eventName[0]);
     // skip inactive module bundles
     if (!$bundle || !$bundle instanceof AbstractModule || $bundle instanceof AbstractModule && $this->kernel->isModuleBundleActive($bundle)) {
         parent::addListenerService($eventName, $callback, $priority);
     }
 }
Example #2
0
 /**
  * Load runtime hook listeners.
  *
  * @return HookDispatcher
  */
 public function loadRuntimeHandlers()
 {
     $handlers = $this->storage->getRuntimeHandlers();
     foreach ($handlers as $handler) {
         if ($handler['serviceid']) {
             $callable = $this->factory->buildService($handler['serviceid'], $handler['classname'], $handler['method']);
             $this->dispatcher->addListenerService($handler['eventname'], $callable);
         } else {
             try {
                 $callable = array($handler['classname'], $handler['method']);
                 $this->dispatcher->addListener($handler['eventname'], $callable);
             } catch (\InvalidArgumentException $e) {
                 throw new Exception\RuntimeException("Hook event handler could not be attached because %s", $e->getMessage(), 0, $e);
             }
         }
     }
     return $this;
 }
 public function testRemoveBeforeDispatch()
 {
     $service = $this->getMock('Symfony\\Component\\EventDispatcher\\Tests\\Service');
     $container = new Container();
     $container->set('service.listener', $service);
     $dispatcher = new ContainerAwareEventDispatcher($container);
     $dispatcher->addListenerService('onEvent', array('service.listener', 'onEvent'));
     $dispatcher->removeListener('onEvent', array($container->get('service.listener'), 'onEvent'));
     $this->assertFalse($dispatcher->hasListeners('onEvent'));
 }
 /**
  * Adds a service as event listener.
  *
  * @param string $eventName Event for which the listener is added
  * @param array  $callback  The service ID of the listener service & the method
  *                          name that has to be called
  * @param int    $priority  The higher this value, the earlier an event listener
  *                          will be triggered in the chain.
  *                          Defaults to 0.
  * @param string $queueName Use null to subscribe to all queues
  * @throws \InvalidArgumentException
  */
 public function addListenerService($eventName, $callback, $priority = 0, $queueName = null)
 {
     parent::addListenerService($eventName, $callback, $priority);
     $this->listenerIds[$eventName][] = array($callback[0], $callback[1], $priority, $queueName);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function addListenerService($eventName, $callback, $priority = 0)
 {
     $this->_wrappedDispatcher->addListenerService($eventName, $callback, $priority);
 }