public function getChoices($key, $section = "default") { $event = new \Symbb\Core\SystemBundle\Event\ConfigChoicesEvent($key, $section, $this->container); $this->dispatcher->dispatch('symbb.config.choices', $event); $options = $event->getChoices(); return $options; }
public function testAddListenerNested() { $called1 = false; $called2 = false; $dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); $dispatcher->addListener('my-event', function () use($dispatcher, &$called1, &$called2) { $called1 = true; $dispatcher->addListener('my-event', function () use(&$called2) { $called2 = true; }); }); $dispatcher->dispatch('my-event'); $this->assertTrue($called1); $this->assertFalse($called2); $dispatcher->dispatch('my-event'); $this->assertTrue($called2); }
public function it_should_get_3rd_party_editor_link(Article $article, TraceableEventDispatcher $dispatcher, GenericEvent $event) { $dispatcher->dispatch('newscoop_admin.editor', Argument::type('Newscoop\\EventDispatcher\\Events\\GenericEvent'))->shouldBeCalled()->willReturn($event); $link = '/admin/some/3rd/party/editor/link/10/1'; $event->hasArgument('link')->willReturn(true); $event->getArgument('link')->willReturn($link); $this->getLink($article)->shouldReturn($link); }
public function testListenerCanRemoveItselfWhenExecuted() { $eventDispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); $listener1 = function () use($eventDispatcher, &$listener1) { $eventDispatcher->removeListener('foo', $listener1); }; $eventDispatcher->addListener('foo', $listener1); $eventDispatcher->addListener('foo', function () { }); $eventDispatcher->dispatch('foo'); $this->assertCount(1, $eventDispatcher->getListeners('foo'), 'expected listener1 to be removed'); }
public function testDispatchNested() { $dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); $loop = 1; $dispatcher->addListener('foo', $listener1 = function () use($dispatcher, &$loop) { ++$loop; if (2 == $loop) { $dispatcher->dispatch('foo'); } }); $dispatcher->dispatch('foo'); }
public function testDispatchReusedEventNested() { $nestedCall = false; $dispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); $dispatcher->addListener('foo', function (Event $e) use($dispatcher) { $dispatcher->dispatch('bar', $e); }); $dispatcher->addListener('bar', function (Event $e) use(&$nestedCall) { $nestedCall = true; }); $this->assertFalse($nestedCall); $dispatcher->dispatch('foo'); $this->assertTrue($nestedCall); }
public function testDispatchCallListeners() { $called = array(); $dispatcher = new EventDispatcher(); $tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch()); $tdispatcher->addListener('foo', $listener1 = function () use(&$called) { $called[] = 'foo1'; }); $tdispatcher->addListener('foo', $listener2 = function () use(&$called) { $called[] = 'foo2'; }); $tdispatcher->dispatch('foo'); $this->assertEquals(array('foo1', 'foo2'), $called); }