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


PHP EventDispatcher::getListeners方法代码示例

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


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

示例1: testCookieIsNotUpdatedWithFalseSetCookieOnChange

 public function testCookieIsNotUpdatedWithFalseSetCookieOnChange()
 {
     $listener = $this->getLocaleUpdateListener(array('cookie'), false);
     $listener->onLocaleChange($this->getFilterLocaleSwitchEvent(false));
     $addedListeners = $this->dispatcher->getListeners(KernelEvents::RESPONSE);
     $this->assertSame(array(), $addedListeners);
 }
开发者ID:Sententiaregum,项目名称:LocaleBundle,代码行数:7,代码来源:LocaleUpdateTest.php

示例2: testConsoleEvent

 public function testConsoleEvent()
 {
     $dispatcher = new EventDispatcher();
     $listener = new DebugHandlersListener(null);
     $app = $this->getMock('Symfony\\Component\\Console\\Application');
     $app->expects($this->once())->method('getHelperSet')->will($this->returnValue(new HelperSet()));
     $command = new Command(__FUNCTION__);
     $command->setApplication($app);
     $event = new ConsoleEvent($command, new ArgvInput(), new ConsoleOutput());
     $dispatcher->addSubscriber($listener);
     $xListeners = array(KernelEvents::REQUEST => array(array($listener, 'configure')), ConsoleEvents::COMMAND => array(array($listener, 'configure')));
     $this->assertSame($xListeners, $dispatcher->getListeners());
     $exception = null;
     $eHandler = new ErrorHandler();
     set_error_handler(array($eHandler, 'handleError'));
     set_exception_handler(array($eHandler, 'handleException'));
     try {
         $dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
     } catch (\Exception $exception) {
     }
     restore_exception_handler();
     restore_error_handler();
     if (null !== $exception) {
         throw $exception;
     }
     $this->assertSame(array(), $dispatcher->getListeners());
     $xHandler = $eHandler->setExceptionHandler('var_dump');
     $this->assertInstanceOf('Closure', $xHandler);
     $app->expects($this->once())->method('renderException');
     $xHandler(new \Exception());
 }
开发者ID:vomasmic,项目名称:symfony,代码行数:31,代码来源:DebugHandlersListenerTest.php

示例3: findEventRecorder

 /**
  * Find event recorder
  *
  * @return EventRecorder|null
  */
 private function findEventRecorder()
 {
     $listeners = $this->eventDispatcher->getListeners('beforeFeature');
     foreach ($listeners as $listener) {
         $formatter = isset($listener[0]) ? $listener[0] : null;
         if (is_object($formatter) && get_class($formatter) === 'saimon7\\ParallelRunner\\Formatter\\EventRecorder') {
             return $formatter;
         }
     }
     return null;
 }
开发者ID:saimon7,项目名称:ParallelRunner,代码行数:16,代码来源:EventService.php

示例4: testGetHasListeners

 public function testGetHasListeners()
 {
     $dispatcher = new EventDispatcher();
     $this->assertFalse($dispatcher->hasListeners('foo'), '->hasListeners() returns false if the event has no listener');
     $dispatcher->connect('foo', 'listenToFoo');
     $this->assertEquals(true, $dispatcher->hasListeners('foo'), '->hasListeners() returns true if the event has some listeners');
     $dispatcher->disconnect('foo', 'listenToFoo');
     $this->assertFalse($dispatcher->hasListeners('foo'), '->hasListeners() returns false if the event has no listener');
     $dispatcher->connect('bar', 'listenToBar');
     $this->assertEquals(array('listenToBar'), $dispatcher->getListeners('bar'), '->getListeners() returns an array of listeners connected to the given event name');
     $this->assertEquals(array(), $dispatcher->getListeners('foobar'), '->getListeners() returns an empty array if no listener are connected to the given event name');
 }
开发者ID:netixpro,项目名称:symfony,代码行数:12,代码来源:EventDispatcherTest.php

示例5: testAddRemoveSubscriber

 public function testAddRemoveSubscriber()
 {
     $dispatcher = new EventDispatcher();
     $tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch());
     $subscriber = new EventSubscriber();
     $tdispatcher->addSubscriber($subscriber);
     $listeners = $dispatcher->getListeners('foo');
     $this->assertCount(1, $listeners);
     $this->assertSame(array($subscriber, 'call'), $listeners[0]);
     $tdispatcher->removeSubscriber($subscriber);
     $this->assertCount(0, $dispatcher->getListeners('foo'));
 }
开发者ID:marchyoung,项目名称:FrameworkBenchmarks,代码行数:12,代码来源:TraceableEventDispatcherTest.php

示例6: getListeners

 /**
  * {@inheritdoc}
  */
 public function getListeners($eventName = null)
 {
     if (null == $eventName || self::BEFORE_ALL_EVENTS === $eventName) {
         return parent::getListeners($eventName);
     }
     return array_merge(parent::getListeners(self::BEFORE_ALL_EVENTS), parent::getListeners($eventName), parent::getListeners(self::AFTER_ALL_EVENTS));
 }
开发者ID:OverByThere,项目名称:Behat,代码行数:10,代码来源:TestworkEventDispatcher.php

示例7: testGetListenersWhenAddedCallbackListenerIsRemoved

 public function testGetListenersWhenAddedCallbackListenerIsRemoved()
 {
     $listener = function () {
     };
     $this->dispatcher->addListener('foo', $listener);
     $this->dispatcher->removeListener('foo', $listener);
     $this->assertSame(array(), $this->dispatcher->getListeners());
 }
开发者ID:Ceciceciceci,项目名称:MySJSU-Class-Registration,代码行数:8,代码来源:AbstractEventDispatcherTest.php

示例8: removeOldListener

 /**
  * Removes old listener from dispatcher
  *
  * @param EventDispatcher $dispatcher
  */
 private function removeOldListener(EventDispatcher $dispatcher)
 {
     $listeners = $dispatcher->getListeners(KernelEvents::REQUEST);
     foreach ($listeners as $listener) {
         if (is_array($listener) && $listener[0] instanceof RouterListenerBase) {
             $dispatcher->removeSubscriber($listener[0]);
         }
     }
 }
开发者ID:gmo,项目名称:common,代码行数:14,代码来源:RouterListener.php

示例9: removeListeners

 /**
  * Removes all registered event listeners.
  */
 private function removeListeners()
 {
     $listeners = $this->dispatcher->getListeners();
     foreach ($listeners as $event => $list) {
         foreach ($list as $listener) {
             $this->dispatcher->removeListener($event, $listener);
         }
     }
 }
开发者ID:box-project,项目名称:builder,代码行数:12,代码来源:BuilderTest.php

示例10: testRemoveSubscriberWithMultipleListeners

 public function testRemoveSubscriberWithMultipleListeners()
 {
     $eventSubscriber = new TestEventSubscriberWithMultipleListeners();
     $this->dispatcher->addSubscriber($eventSubscriber);
     $this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
     $this->assertCount(2, $this->dispatcher->getListeners(self::preFoo));
     $this->dispatcher->removeSubscriber($eventSubscriber);
     $this->assertFalse($this->dispatcher->hasListeners(self::preFoo));
 }
开发者ID:mickdane,项目名称:zidisha,代码行数:9,代码来源:EventDispatcherTest.php

示例11: testShouldFindAndAttachListenersToDispatcher

 public function testShouldFindAndAttachListenersToDispatcher()
 {
     $dispatcher = new EventDispatcher();
     // There are no listeners on new dispatcher
     $this->assertEmpty($dispatcher->getListeners());
     $this->instantiator->instantiate($dispatcher, __DIR__);
     $listeners = $dispatcher->getListeners();
     $this->assertNotEmpty($listeners);
     $this->assertArrayHasKey('foo', $listeners);
 }
开发者ID:mhujer,项目名称:steward,代码行数:10,代码来源:ListenerInstantiatorTest.php

示例12: getListeners

 public function getListeners($eventName = null)
 {
     if (null === $eventName) {
         foreach ($this->listenerIds as $serviceEventName => $args) {
             $this->lazyLoad($serviceEventName);
         }
     } else {
         $this->lazyLoad($eventName);
     }
     return parent::getListeners($eventName);
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:11,代码来源:ContainerAwareEventDispatcher.php

示例13: getListeners

 /**
  * @inheritdoc
  */
 public function getListeners($eventName = null)
 {
     $processedListeners = array();
     foreach (parent::getListeners($eventName) as $listener) {
         if (is_string($listener)) {
             $processedListeners[] = $this->getCallable($listener);
         } else {
             $processedListeners[] = $listener;
         }
     }
     return $processedListeners;
 }
开发者ID:trapp,项目名称:pimpleaware-eventdispatcher,代码行数:15,代码来源:PimpleAwareEventDispatcher.php

示例14: getListeners

 /**
  * {@inheritdoc}
  */
 public function getListeners($eventName = null)
 {
     if ($eventName === null) {
         return parent::getListeners($eventName);
     }
     $listeners = [];
     foreach (parent::getListeners() as $name => $eventListeners) {
         $namePattern = str_replace(["*", "#"], ["(\\w+)", "([\\w\\.]+)"], $name);
         if (preg_match("~^{$namePattern}\$~", $eventName)) {
             $listeners = array_merge($listeners, $eventListeners);
         }
     }
     return $listeners;
 }
开发者ID:gallna,项目名称:amqp-event,代码行数:17,代码来源:Dispatcher.php

示例15: get

 /**
  * @see AbstractDispatcherAdapter::get
  */
 public function get($name)
 {
     return $this->dispatcher->getListeners($name);
 }
开发者ID:bee4,项目名称:events,代码行数:7,代码来源:SymfonyEventDispatcherAdapter.php


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