本文整理匯總了PHP中Symfony\Component\EventDispatcher\Event::setDispatcher方法的典型用法代碼示例。如果您正苦於以下問題:PHP Event::setDispatcher方法的具體用法?PHP Event::setDispatcher怎麽用?PHP Event::setDispatcher使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\EventDispatcher\Event
的用法示例。
在下文中一共展示了Event::setDispatcher方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: dispatch
/**
* Dispatches an event to all registered listeners.
*
* @param string $eventName The name of the event to dispatch. The name of
* the event is the name of the method that is
* invoked on listeners.
* @param Event $event The event to pass to the event handlers/listeners.
* If not supplied, an empty Event instance is created.
*
* @return Event
*
* @api
*/
public function dispatch($eventName, Event $event = null)
{
if ($event == null) {
$event = new Event();
}
$event->setName($eventName);
$event->setDispatcher($this);
$this->laravelDispatcher->fire($eventName, $event);
$this->symfonyDispatcher->dispatch($eventName, $event);
$event->setDispatcher($this);
return $event;
}
示例2: testSetDispatcher
public function testSetDispatcher()
{
$this->event->setDispatcher($this->dispatcher);
$this->assertSame($this->dispatcher, $this->event->getDispatcher());
}
示例3: onEvent
/**
* @param Event $event
* @param string $eventName
* @param EventDispatcherInterface $dispatcher
*
* @return void
*/
public function onEvent(Event $event, $eventName, EventDispatcherInterface $dispatcher)
{
if ($this->opponentPID === null) {
return;
}
$event->setDispatcher(new TransportableEventDispatcher());
$serialized = serialize($event);
$sendData = pack('S', strlen($eventName)) . $eventName . pack('N', strlen($serialized)) . $serialized . pack('S', $this->getDispatcherId($dispatcher));
if (fwrite($this->bridge[$this->mode], $sendData) === false) {
throw new \RuntimeException('Could not write event to socket.');
}
$this->sendPollSignal();
}
示例4: testLegacySetDispatcher
public function testLegacySetDispatcher()
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$this->event->setDispatcher($this->dispatcher);
$this->assertSame($this->dispatcher, $this->event->getDispatcher());
}
示例5: testHasListenersOnLazyLoad
public function testHasListenersOnLazyLoad()
{
$event = new Event();
$service = $this->getMock('Symfony\\Component\\EventDispatcher\\Tests\\Service');
$container = new Container();
$container->set('service.listener', $service);
$dispatcher = new ContainerAwareEventDispatcher($container);
$dispatcher->addListenerService('onEvent', array('service.listener', 'onEvent'));
$event->setDispatcher($dispatcher);
$event->setName('onEvent');
$service->expects($this->once())->method('onEvent')->with($event);
$this->assertTrue($dispatcher->hasListeners());
if ($dispatcher->hasListeners('onEvent')) {
$dispatcher->dispatch('onEvent');
}
}
示例6: dispatch
/**
* {@inheritdoc}
*/
public function dispatch($event_name, Event $event = NULL)
{
if ($event === NULL) {
$event = new Event();
}
$event->setDispatcher($this);
$event->setName($event_name);
if (isset($this->listeners[$event_name])) {
// Sort listeners if necessary.
if (isset($this->unsorted[$event_name])) {
krsort($this->listeners[$event_name]);
unset($this->unsorted[$event_name]);
}
// Invoke listeners and resolve callables if necessary.
foreach ($this->listeners[$event_name] as $priority => &$definitions) {
foreach ($definitions as $key => &$definition) {
if (!isset($definition['callable'])) {
$definition['callable'] = [$this->container->get($definition['service'][0]), $definition['service'][1]];
}
$definition['callable']($event, $event_name, $this);
if ($event->isPropagationStopped()) {
return $event;
}
}
}
}
return $event;
}
示例7: testHasListenersOnLazyLoad
public function testHasListenersOnLazyLoad()
{
$event = new Event();
$service = $this->getMock('SilexCMF\\Core\\Tests\\Service');
$container = new Application();
$container['service.listener'] = Application::share(function () use($service) {
return $service;
});
$dispatcher = new PimpleAwareEventDispatcher();
$dispatcher->setContainer($container);
$dispatcher->addListenerService('onEvent', ['service.listener', 'onEvent']);
$event->setDispatcher($dispatcher);
$event->setName('onEvent');
$service->expects(static::once())->method('onEvent')->with($event);
static::assertTrue($dispatcher->hasListeners());
if ($dispatcher->hasListeners('onEvent')) {
$dispatcher->dispatch('onEvent');
}
}