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


PHP EventManager::getListeners方法代码示例

本文整理汇总了PHP中Zend\EventManager\EventManager::getListeners方法的典型用法代码示例。如果您正苦于以下问题:PHP EventManager::getListeners方法的具体用法?PHP EventManager::getListeners怎么用?PHP EventManager::getListeners使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\EventManager\EventManager的用法示例。


在下文中一共展示了EventManager::getListeners方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testEventListeners

 public function testEventListeners()
 {
     $events = new EventManager();
     $events->attachAggregate($this->strategy);
     $listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH_ERROR);
     $expectedCallback = array($this->strategy, 'prepareExceptionViewModel');
     $expectedPriority = 1;
     $found = false;
     foreach ($listeners as $listener) {
         $callback = $listener->getCallback();
         if ($callback === $expectedCallback) {
             if ($listener->getMetadatum('priority') == $expectedPriority) {
                 $found = true;
                 break;
             }
         }
     }
     $this->assertTrue($found, 'MvcEvent::EVENT_DISPATCH_ERROR not found');
     $listeners = $events->getListeners(MvcEvent::EVENT_RENDER_ERROR);
     $expectedCallback = array($this->strategy, 'prepareExceptionViewModel');
     $expectedPriority = 1;
     $found = false;
     foreach ($listeners as $listener) {
         $callback = $listener->getCallback();
         if ($callback === $expectedCallback) {
             if ($listener->getMetadatum('priority') == $expectedPriority) {
                 $found = true;
                 break;
             }
         }
     }
     $this->assertTrue($found, 'MvcEvent::EVENT_RENDER_ERROR not found');
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:33,代码来源:ExceptionStrategyTest.php

示例2: testCanDetachListenersFromEventManager

 public function testCanDetachListenersFromEventManager()
 {
     $events = new EventManager();
     $events->attachAggregate($this->strategy);
     $this->assertEquals(1, count($events->getListeners(MvcEvent::EVENT_RENDER)));
     $events->detachAggregate($this->strategy);
     $this->assertEquals(0, count($events->getListeners(MvcEvent::EVENT_RENDER)));
 }
开发者ID:razvansividra,项目名称:pnlzf2-1,代码行数:8,代码来源:DefaultRenderingStrategyTest.php

示例3: testEventManagerHasDefaultListeners

 /**
  * 测试能正常注册身份验证过程中的事件监听器。
  */
 public function testEventManagerHasDefaultListeners()
 {
     $eventManager = new EventManager();
     $eventManager->attach($this->stub);
     $this->assertFalse($eventManager->getListeners(Event::EVENT_VERIFY_POST)->isEmpty());
     $this->assertFalse($eventManager->getListeners(Event::EVENT_TOKEN_POST)->isEmpty());
     $this->assertFalse($eventManager->getListeners(Event::EVENT_FAILURE)->isEmpty());
 }
开发者ID:starflash,项目名称:MobilePf-ZF2-Example,代码行数:11,代码来源:AuthLoggerListenerAbstractTest.php

示例4: testAttach

 public function testAttach()
 {
     $em = new EventManager();
     $this->assertEmpty($em->getListeners(ViewEvent::EVENT_RENDERER));
     $this->assertEmpty($em->getListeners(ViewEvent::EVENT_RESPONSE));
     $this->strategy->attach($em);
     $this->assertCount(1, $em->getListeners(ViewEvent::EVENT_RENDERER));
     $this->assertCount(1, $em->getListeners(ViewEvent::EVENT_RESPONSE));
 }
开发者ID:acelaya,项目名称:zf2-acyaml,代码行数:9,代码来源:YamlStrategyTest.php

示例5: testDetachesListeners

 public function testDetachesListeners()
 {
     $events = new EventManager();
     $events->attachAggregate($this->listener);
     $listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH);
     $this->assertEquals(2, count($listeners));
     $events->detachAggregate($this->listener);
     $listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH);
     $this->assertEquals(0, count($listeners));
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:10,代码来源:CreateViewModelListenerTest.php

示例6: testAttach

 public function testAttach()
 {
     $eventManager = new EventManager();
     $listener = new BodyClassListener(new BodyClass());
     $before = $eventManager->getListeners(\Zend\Mvc\MvcEvent::EVENT_DISPATCH);
     $this->assertCount(0, $before);
     $eventManager->attach($listener);
     $after = $eventManager->getListeners(\Zend\Mvc\MvcEvent::EVENT_DISPATCH);
     $this->assertCount(1, $after);
 }
开发者ID:adamdyson,项目名称:ConLayout,代码行数:10,代码来源:BodyClassListenerTest.php

示例7: testEventSubscribers

 public function testEventSubscribers()
 {
     $manager = new EventManager();
     $this->assertCount(0, $manager->getListeners(ViewEvent::EVENT_RENDERER), 'Renderer listener before attach');
     $this->assertCount(0, $manager->getListeners(ViewEvent::EVENT_RESPONSE), 'Response listener before attach');
     $this->strategy->attach($manager);
     $this->assertCount(1, $manager->getListeners(ViewEvent::EVENT_RENDERER), 'Renderer listener after attach');
     $this->assertCount(1, $manager->getListeners(ViewEvent::EVENT_RESPONSE), 'Response listener after attach');
     $this->strategy->detach($manager);
     $this->assertCount(0, $manager->getListeners(ViewEvent::EVENT_RENDERER), 'Renderer listener after detach');
     $this->assertCount(0, $manager->getListeners(ViewEvent::EVENT_RESPONSE), 'Response listener after detach');
 }
开发者ID:raykolbe,项目名称:DOMPDFModule,代码行数:12,代码来源:PdfStrategyTest.php

示例8: testListenerAttached

 public function testListenerAttached()
 {
     $events = new EventManager();
     $events->attach($this->listener);
     $listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH_ERROR);
     $this->assertEquals(1, count($listeners));
     $listeners = $events->getListeners(MvcEvent::EVENT_RENDER_ERROR);
     $this->assertEquals(1, count($listeners));
     $events->detach($this->listener);
     $listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH_ERROR);
     $this->assertEquals(0, count($listeners));
     $listeners = $events->getListeners(MvcEvent::EVENT_RENDER_ERROR);
     $this->assertEquals(0, count($listeners));
 }
开发者ID:simplicity-ag,项目名称:NewRelic,代码行数:14,代码来源:ErrorListenerTest.php

示例9: testDetachesListeners

 public function testDetachesListeners()
 {
     $events = new EventManager();
     $events->attachAggregate($this->listener);
     $listeners = $events->getListeners('dispatch');
     $this->assertEquals(1, count($listeners));
     $events->detachAggregate($this->listener);
     $listeners = $events->getListeners('dispatch');
     $this->assertEquals(0, count($listeners));
 }
开发者ID:navtis,项目名称:xerxes-pazpar2,代码行数:10,代码来源:CreateViewModelFromArrayListenerTest.php

示例10: testAttachesToRouteEventAtNegativePriority

 public function testAttachesToRouteEventAtNegativePriority()
 {
     $events = new EventManager();
     $events->attach($this->listener);
     $listeners = $events->getListeners('route');
     $this->assertEquals(1, count($listeners));
     $this->assertTrue($listeners->hasPriority(-41));
     $callback = $listeners->getIterator()->current()->getCallback();
     $test     = array_shift($callback);
     $this->assertSame($this->listener, $test);
 }
开发者ID:jbarentsen,项目名称:drb,代码行数:11,代码来源:VersionListenerTest.php

示例11: removeListener

 /**
  * {@inheritDoc}
  */
 public function removeListener($eventName, $listener)
 {
     $listeners = $this->eventManager->getListeners($eventName);
     foreach ($listeners as $callbackHanler) {
         $callback = $callbackHanler->getCallback();
         if (is_array($callback)) {
             if (is_array($listener)) {
                 if ($callback[0] === $listener[0] && $callback[1] === $listener[1]) {
                     return $this->eventManager->detach($callbackHanler);
                 }
             } else {
                 continue;
             }
         }
         if ($callback === $listener) {
             return $this->eventManager->detach($callbackHanler);
         }
     }
     return true;
 }
开发者ID:malocher,项目名称:zf2-event-store-module,代码行数:23,代码来源:EventManagerProxy.php

示例12: testListenerAttachesDispatchEventAtExpectedPriority

 public function testListenerAttachesDispatchEventAtExpectedPriority()
 {
     $events = new EventManager();
     $events->attachAggregate($this->listener);
     $listeners = $events->getListeners(MvcEvent::EVENT_DISPATCH);
     $expectedCallback = [$this->listener, 'injectActionHandles'];
     $expectedPriority = 1000;
     $found = false;
     foreach ($listeners as $listener) {
         $callback = $listener->getCallback();
         if ($callback === $expectedCallback) {
             if ($listener->getMetadatum('priority') == $expectedPriority) {
                 $found = true;
                 break;
             }
         }
     }
     $this->assertTrue($found, 'Listener not found');
 }
开发者ID:adamdyson,项目名称:ConLayout,代码行数:19,代码来源:ActionHandlesListenerTest.php

示例13: getListenersForEvent

 /**
  * Retrieve an interable list of listeners for an event.
  *
  * Given an event and an event manager, returns an iterator with the
  * listeners for that event, in priority order.
  *
  * If $withPriority is true, the key values will be the priority at which
  * the given listener is attached.
  *
  * Do not pass $withPriority if you want to cast the iterator to an array,
  * as many listeners will likely have the same priority, and thus casting
  * will collapse to the last added.
  *
  * @param string $event
  * @param EventManager $events
  * @param bool $withPriority
  * @return \Traversable
  */
 private function getListenersForEvent($event, EventManager $events, $withPriority = false)
 {
     $listeners = $events->getListeners($event);
     return $this->traverseListeners($listeners, $withPriority);
 }
开发者ID:kienbk1910,项目名称:RDCAdmin,代码行数:23,代码来源:EventListenerIntrospectionTrait.php

示例14: testAttach

 public function testAttach()
 {
     $this->strategy->attach($this->em);
     $this->assertCount(1, $this->em->getListeners(ViewEvent::EVENT_RENDERER));
     $this->assertCount(1, $this->em->getListeners(ViewEvent::EVENT_RESPONSE));
 }
开发者ID:adamdyson,项目名称:ConLayout,代码行数:6,代码来源:BlockStrategyTest.php

示例15: testAttachAndDetachListener

 public function testAttachAndDetachListener()
 {
     $events = new EventManager();
     $events->attach($this->listener);
     $listeners = $events->getListeners(MvcEvent::EVENT_FINISH);
     $this->assertEquals(1, count($listeners));
     $events->detach($this->listener);
     $listeners = $events->getListeners(MvcEvent::EVENT_FINISH);
     $this->assertEquals(0, count($listeners));
 }
开发者ID:simplicity-ag,项目名称:NewRelic,代码行数:10,代码来源:ResponseListenerTest.php


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