本文整理汇总了PHP中EventManager::attachHandler方法的典型用法代码示例。如果您正苦于以下问题:PHP EventManager::attachHandler方法的具体用法?PHP EventManager::attachHandler怎么用?PHP EventManager::attachHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventManager
的用法示例。
在下文中一共展示了EventManager::attachHandler方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAttachAndDetach
public function testAttachAndDetach()
{
$subject1 = $this->getMockBuilder('Jivoo\\Core\\EventSubject')->getMock();
$subject1->method('getEvents')->willReturn(array('someEvent'));
$subject2 = $this->getMockBuilder('Jivoo\\Core\\EventSubject')->getMock();
$subject2->method('getEvents')->willReturn(array('someEvent'));
$em1 = new EventManager($subject1);
$em2 = new EventManager($subject2, $em1);
$c = function () {
return false;
};
$em1->attachHandler('someEvent', $c);
$this->assertFalse($em1->trigger('someEvent'));
$em1->detachHandler('someEvent', $c);
$this->assertTrue($em1->trigger('someEvent'));
$em2->attachHandler(get_class($subject1) . '.someEvent', $c);
$this->assertFalse($em2->trigger(get_class($subject1) . '.someEvent'));
$em2->detachHandler(get_class($subject1) . '.someEvent', $c);
$this->assertTrue($em2->trigger(get_class($subject1) . '.someEvent'));
$this->assertThrows('Jivoo\\Core\\EventException', function () use($em1) {
$em1->attachHandler('someOtherEvent', null);
});
$this->assertThrows('Jivoo\\Core\\EventException', function () use($em1) {
$em1->trigger('someOtherEvent');
});
}
示例2: one
/**
* {@inheritdoc}
*/
public function one($name, callable $callback)
{
$this->e->attachHandler($name, $callback, true);
}