addCallbacks() public method

Add one or more callbacks
public addCallbacks ( string $name, array $events, array $users = [] ) : self
$name string The name of the handler that owns the callback
$events array Which events the callback will trigger for
$users array User filter for the events
return self
Example #1
0
 /**
  * @covers Imbo\EventManager\EventManager::getHandlerInstance
  */
 public function testCanInjectParamsInConstructor()
 {
     $listenerClassName = __NAMESPACE__ . '\\Listener';
     $this->manager->addEventHandler('someHandler', $listenerClassName, array('param'));
     $this->manager->addCallbacks('someHandler', $listenerClassName::getSubscribedEvents());
     $this->expectOutputString('a:1:{i:0;s:5:"param";}');
     $this->manager->trigger('getParams');
 }
Example #2
0
 /**
  * @see https://github.com/imbo/imbo/issues/251
  *
  * This test is best run with "In the Ghetto" blasting on the stereo
  */
 public function testHasHigherPriorityThanTheStatsResource()
 {
     $statsAccess = new StatsAccess();
     $statsResource = new StatsResource();
     $eventManager = new EventManager();
     $eventManager->addEventHandler('statsAccess', $statsAccess);
     $eventManager->addCallbacks('statsAccess', StatsAccess::getSubscribedEvents());
     $eventManager->addEventHandler('statsResource', $statsResource);
     $eventManager->addCallbacks('statsResource', StatsResource::getSubscribedEvents());
     $callbacks = new ReflectionProperty($eventManager, 'callbacks');
     $callbacks->setAccessible(true);
     $handlersForGet = $callbacks->getValue($eventManager)['stats.get'];
     $handlersForHead = $callbacks->getValue($eventManager)['stats.head'];
     $this->assertSame($statsAccess, $eventManager->getHandlerInstance($handlersForGet->extract()['handler']));
     $this->assertSame($statsResource, $eventManager->getHandlerInstance($handlersForGet->extract()['handler']));
     $this->assertSame($statsAccess, $eventManager->getHandlerInstance($handlersForHead->extract()['handler']));
     $this->assertSame($statsResource, $eventManager->getHandlerInstance($handlersForHead->extract()['handler']));
 }