本文整理汇总了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);
}
示例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());
}
示例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;
}
示例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');
}
示例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'));
}
示例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));
}
示例7: testGetListenersWhenAddedCallbackListenerIsRemoved
public function testGetListenersWhenAddedCallbackListenerIsRemoved()
{
$listener = function () {
};
$this->dispatcher->addListener('foo', $listener);
$this->dispatcher->removeListener('foo', $listener);
$this->assertSame(array(), $this->dispatcher->getListeners());
}
示例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]);
}
}
}
示例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);
}
}
}
示例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));
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例15: get
/**
* @see AbstractDispatcherAdapter::get
*/
public function get($name)
{
return $this->dispatcher->getListeners($name);
}