Ejemplo n.º 1
0
 /**
  * registerListeners
  *
  * @param Dispatcher $dispatcher
  *
  * @return  void
  */
 public function registerListeners(Dispatcher $dispatcher)
 {
     $config = Ioc::getConfig();
     $plugins = $config->get('plugins', array());
     foreach ($plugins as $plugin) {
         if (class_exists($plugin) && is_subclass_of($plugin, 'Vaseman\\Plugin\\AbstractPlugin') && $plugin::$isEnabled) {
             $dispatcher->addListener(new $plugin());
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Test the triggerEvent method with a previously registered event.
  *
  * @return  void
  *
  * @covers  Windwalker\Event\Dispatcher::triggerEvent
  * @since   1.0
  */
 public function testTriggerEventRegistered()
 {
     $event = new Event('onSomething');
     $mockedListener = $this->getMock('Windwalker\\Event\\Test\\Stub\\SomethingListener', array('onSomething'));
     $mockedListener->expects($this->once())->method('onSomething')->with($event);
     $this->instance->addEvent($event);
     $this->instance->addListener($mockedListener);
     $this->instance->triggerEvent('onSomething');
 }
Ejemplo n.º 3
0
 /**
  * testTriggerEventReference
  *
  * @return  void
  */
 public function testTriggerEventReference()
 {
     $event = new Event('onSomething');
     $foo = 'foo';
     $args = array('foo' => &$foo);
     $this->instance->triggerEvent($event, $args);
     $event->setArgument('foo', 'bar');
     $this->assertEquals('bar', $foo);
 }
Ejemplo n.º 4
0
 /**
  * triggerEvent
  *
  * @param   string|Event  $event
  * @param   array         $args
  *
  * @return  Event
  *
  * @since   2.1
  */
 public function triggerEvent($event, $args = array())
 {
     $dispatcher = $this->getDispatcher();
     if (!$dispatcher instanceof DispatcherInterface) {
         return null;
     }
     $args['record'] = $this;
     $event = $this->dispatcher->triggerEvent($event, $args);
     $innerListener = array($this, $event->getName());
     if (!$event->isStopped() && is_callable($innerListener)) {
         call_user_func($innerListener, $event);
     }
     return $event;
 }