本文整理汇总了PHP中EventManager::attachListener方法的典型用法代码示例。如果您正苦于以下问题:PHP EventManager::attachListener方法的具体用法?PHP EventManager::attachListener怎么用?PHP EventManager::attachListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventManager
的用法示例。
在下文中一共展示了EventManager::attachListener方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetEventNames
/**
* @covers Phossa\Event\EventManager::getEventNames
*/
public function testGetEventNames()
{
$l = new Listener();
$this->object->attachListener($l);
// check attached event
$evts = $this->object->getEventNames();
$this->assertTrue($evts === array_keys($l->getEventsListening()));
}
示例2: testTriggerEvent
/**
* @covers Phossa\Event\EventAwareStatic::triggerEventStatically
*/
public function testTriggerEvent()
{
$manager = new EventManager();
require_once __DIR__ . '/Listener.php';
require_once __DIR__ . '/ListenerStatic.php';
$manager->attachListener(new Listener());
$manager->attachListener('Phossa\\Event\\ListenerStatic');
EventAwareStatic::setEventManagerStatically($manager);
$e1 = EventAwareStatic::triggerEventStatically('evtTest4');
// has 'testY'
$this->assertArrayHasKey('testY', $e1->getProperties());
// stopped after 'testY'
$this->assertArrayNotHasKey('testZ', $e1->getProperties());
// both object/static listener has 'evtTest2'
$e2 = EventAwareStatic::triggerEventStatically('evtTest2', ['x' => 'xx']);
$this->assertArrayHasKey('testD', $e2->getProperties());
$this->assertArrayHasKey('s_testDD', $e2->getProperties());
$this->assertArrayHasKey('x', $e2->getProperties());
}
示例3: testTriggerEvent
/**
* @covers Phossa\Event\EventAware::triggerEvent
*/
public function testTriggerEvent()
{
$manager = new EventManager();
require_once __DIR__ . '/Listener.php';
require_once __DIR__ . '/ListenerStatic.php';
$manager->attachListener(new Listener());
$manager->attachListener('Phossa\\Event\\ListenerStatic');
// set event manager
$this->object->setEventManager($manager, new Event('prototype'));
$e1 = $this->object->triggerEvent('evtTest4');
$this->assertArrayHasKey('testY', $e1->getProperties());
// stopped after 'testY'
$this->assertArrayNotHasKey('testZ', $e1->getProperties());
$this->assertEquals(5, count($e1->getProperties()));
// both object/static class has 'evtTest2'
$e2 = $this->object->triggerEvent('evtTest2');
$this->assertArrayHasKey('testD', $e2->getProperties());
$this->assertArrayHasKey('s_testDD', $e2->getProperties());
$this->assertEquals(5, count($e2->getProperties()));
}
示例4: testListener
public function testListener()
{
$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);
$l = $this->getMockBuilder('Jivoo\\Core\\EventListener')->setMethods(array('getEventHandlers', 'someEvent'))->getMock();
$l->method('getEventHandlers')->wilLReturn(array(get_class($subject2) . '.someEvent'));
$l->expects($this->once())->method('someEvent')->willReturn(false);
$em1->attachListener($l);
$this->assertFalse($em2->trigger('someEvent'));
$em1->detachListener($l);
$this->assertTrue($em2->trigger('someEvent'));
}
示例5: attachEventListener
/**
* {@inheritdoc}
*/
public function attachEventListener(EventListener $listener)
{
$this->e->attachListener($listener);
}