本文整理汇总了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');
}
示例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)));
}
示例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());
}
示例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));
}
示例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));
}
示例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);
}
示例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');
}
示例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));
}
示例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));
}
示例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);
}
示例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;
}
示例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');
}
示例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);
}
示例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));
}
示例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));
}