当前位置: 首页>>代码示例>>PHP>>正文


PHP EventManager::attachListener方法代码示例

本文整理汇总了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()));
 }
开发者ID:phossa,项目名称:phossa-event,代码行数:11,代码来源:EventManagerTest.php

示例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());
 }
开发者ID:phossa,项目名称:phossa-event,代码行数:22,代码来源:EventAwareStaticTest.php

示例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()));
 }
开发者ID:phossa,项目名称:phossa-event,代码行数:23,代码来源:EventAwareTest.php

示例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'));
 }
开发者ID:jivoo,项目名称:jivoo,代码行数:16,代码来源:EventManagerTest.php

示例5: attachEventListener

 /**
  * {@inheritdoc}
  */
 public function attachEventListener(EventListener $listener)
 {
     $this->e->attachListener($listener);
 }
开发者ID:jivoo,项目名称:core,代码行数:7,代码来源:EventSubjectBase.php


注:本文中的EventManager::attachListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。