本文整理汇总了PHP中Symfony\Component\EventDispatcher\EventDispatcherInterface::addListener方法的典型用法代码示例。如果您正苦于以下问题:PHP EventDispatcherInterface::addListener方法的具体用法?PHP EventDispatcherInterface::addListener怎么用?PHP EventDispatcherInterface::addListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\EventDispatcher\EventDispatcherInterface
的用法示例。
在下文中一共展示了EventDispatcherInterface::addListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: notify
public function notify(OrderCreatedEvent $event)
{
$captureToken = $this->tokenFactory->createToken($event->getOrder(), $event->getGatewayName());
$this->eventDispatcher->addListener(KernelEvents::RESPONSE, function (FilterResponseEvent $event) use($captureToken) {
$event->setResponse(new RedirectResponse($captureToken->getTargetUrl()));
}, -1000);
}
示例2: addListener
/**
* {@inheritDoc}
*/
public function addListener($eventName, $listener, $priority = 0)
{
if (!$this->primaryEventDispatcher) {
throw new \RuntimeException('Undefined primary event dispatcher.');
}
$this->primaryEventDispatcher->addListener($eventName, $listener, $priority);
}
示例3: execute
/**
* Executes controller.
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return null|integer
*/
public function execute(InputInterface $input, OutputInterface $output)
{
if (!$input->getOption('stop-on-failure')) {
return null;
}
$this->eventDispatcher->addListener(ScenarioTested::AFTER, array($this, 'exitOnFailure'), -100);
$this->eventDispatcher->addListener(ExampleTested::AFTER, array($this, 'exitOnFailure'), -100);
}
示例4: registerListeners
public function registerListeners(EventDispatcherInterface $dispatcher)
{
// Pre-render filters
$dispatcher->addListener(Events::preRender($this), array($this, 'preFilterLayout'));
$dispatcher->addListener(Events::preRender($this), array($this, 'preFilterRelativePosition'));
// Post-render filters
$dispatcher->addListener(Events::postRender($this), array($this, 'postFilterLayout'));
}
示例5: __construct
/**
* @param EventDispatcherInterface $dispatcher
* @param OutputInterface $output
*/
public function __construct(EventDispatcherInterface $dispatcher, OutputInterface $output)
{
$this->output = $output;
$dispatcher->addListener('elasticsearch.has_started_handling', [$this, 'onStartedHandling']);
$dispatcher->addListener('elasticsearch.has_started_providing', [$this, 'onStartedProviding']);
$dispatcher->addListener('elasticsearch.has_provided_document', [$this, 'onProvidedDocument']);
$dispatcher->addListener('elasticsearch.has_finished_providing', [$this, 'onFinishedProviding']);
}
示例6: __construct
/**
* @param Router $router
* @param Request $request
* @param ActionFactoryInterface $action_factory
* @param PresenterInterface $presenter
* @param EventDispatcherInterface $event_dispatcher
* @param EventHandlerInterface $exception_handler
*/
public function __construct(Router $router, Request $request, ActionFactoryInterface $action_factory, PresenterInterface $presenter, EventDispatcherInterface $event_dispatcher, EventHandlerInterface $exception_handler)
{
$this->router = $router;
$this->request = $request;
$this->action_factory = $action_factory;
$this->presenter = $presenter;
$this->events = $event_dispatcher;
$this->events->addListener(DispatchEvents::DISPATCH_ERROR, $exception_handler, DispatchEvents::LATE_EVENT);
}
示例7: __invoke
public function __invoke($name, $value, $options)
{
$placeholder = '<!-- ' . uniqid('section.') . ' -->';
$this->events->addListener(KernelEvents::RESPONSE, function (FilterResponseEvent $event) use($value, $placeholder) {
$response = $event->getResponse();
$response->setContent(str_replace($placeholder, $this->render($value), $response->getContent()));
}, 10);
return $placeholder;
}
示例8: prepareForInitCollections
protected function prepareForInitCollections()
{
$this->user->expects($this->any())->method('getUID')->will($this->returnValue('alice'));
$this->userSession->expects($this->once())->method('getUser')->will($this->returnValue($this->user));
$this->dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function (CommentsEntityEvent $event) {
$event->addEntityCollection('files', function () {
return true;
});
});
}
示例9: execute
/**
* {@inheritdoc}
*/
public function execute($object = NULL)
{
$url = $this->urlGenerator->generateFromPath($this->configuration['url'], array('absolute' => TRUE));
$response = new RedirectResponse($url);
$listener = function ($event) use($response) {
$event->setResponse($response);
};
// Add the listener to the event dispatcher.
$this->dispatcher->addListener(KernelEvents::RESPONSE, $listener);
}
示例10: registerListeners
protected function registerListeners(EventDispatcherInterface $dispatcher)
{
// $dispatcher->addListener takes two parameters: an event name, and a callable
// Default events names can be found in Manialib\XML\Rendering\Events
// There are some "global" events
$dispatcher->addListener(Events::PRE_RENDER, array($this, 'preGlobalRender'));
// But also some events related to the current instance.
// Manialib\XML\Rendering\Events provides shortcuts to generate instance-related event names
$dispatcher->addListener(Events::preRender($this), array($this, 'preThisRender'));
// Full documetation of Event Dispatcher at
// http://symfony.com/doc/current/components/event_dispatcher/index.html
}
示例11: add
/**
* @param StateMachineInterface|Callback $smOrCallback
* @param string $event
* @param callable $callable
* @param array $specs
*
* @return CallbackHandler
*/
protected function add($smOrCallback, $event, $callable = null, array $specs = array())
{
if ($smOrCallback instanceof Callback) {
$this->dispatcher->addListener($event, $smOrCallback);
return $this;
}
trigger_error('Use of CallbackHandler::add without a Callback instance is deprecated and will be removed in 2.0', E_USER_DEPRECATED);
$specs = $this->specResolver->resolve($specs);
$callback = CallbackBuilder::create($smOrCallback, $specs['from'], $specs['to'], $specs['on'], $callable)->getCallback();
$this->dispatcher->addListener($event, $callback);
return $this;
}
示例12: setupProgressListeners
/**
* @param EventDispatcherInterface $dispatcher
* @param ProgressHelper $progress
* @param OutputInterface $output
*/
protected function setupProgressListeners(EventDispatcherInterface $dispatcher, ProgressHelper $progress, OutputInterface $output)
{
$dispatcher->addListener(IoEvents::PRE_EXPORT_FEED, function (ExportFeedEvent $event) use($progress, $output) {
$output->writeln(sprintf('Exporting feed for <info>%s</info> to <info>%s</info>', $event->getType()->getName(), $event->getFile()));
$progress->start($output, $event->getTotal());
});
$dispatcher->addListener(IoEvents::POST_EXPORT_ITEM, function () use($progress) {
$progress->advance(1);
});
$dispatcher->addListener(IoEvents::POST_EXPORT_FEED, function () use($progress) {
$progress->finish();
});
}
示例13: attachEvents
/**
* @inheritDoc
*/
protected function attachEvents(OutputInterface $output, EventDispatcherInterface $dispatcher)
{
$this->output = $output;
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_NORMAL) {
$dispatcher->addListener(EventInterface::COLLECTION_BEFORE, [$this, 'onCollectionBefore']);
$dispatcher->addListener(EventInterface::COLLECTION_AFTER, [$this, 'onCollectionAfter']);
$dispatcher->addListener(EventInterface::MIGRATION_BEFORE, [$this, 'onMigrationBefore']);
$dispatcher->addListener(EventInterface::MIGRATION_AFTER, [$this, 'onMigrationAfter']);
}
if ($this->saveChanges) {
$dispatcher->addListener(EventInterface::MIGRATION_AFTER, [$this, 'saveVersionListener']);
}
}
示例14: createGrid
/**
* @ActivityListQueryDesigner $queryDesigner
*
* @return DatagridInterface
*/
public function createGrid(ActivityListQueryDesigner $source)
{
$this->datagridConfigurationBuilder->setGridName('related-activity');
$this->datagridConfigurationBuilder->setSource($source);
$config = $this->datagridConfigurationBuilder->getConfiguration();
$stopPropagationListener = function (Event $e) {
$e->stopPropagation();
};
$this->eventDispatcher->addListener(BuildBefore::NAME, $stopPropagationListener, 255);
$grid = $this->gridBuilderLink->getService()->build($config, new ParameterBag());
$this->eventDispatcher->removeListener(BuildBefore::NAME, $stopPropagationListener);
return $grid;
}
示例15: subscribe
/**
* {@inheritdoc}
*/
protected function subscribe(EventDispatcherInterface $dispatcher)
{
// Install the YAML configuration file.
$this->getConfig();
/** @var Application $app */
$app = $this->getContainer();
// Storage events test callback class
$storageEventTests = new StorageEventTests($app['storage']);
// Storage event listeners
$dispatcher->addListener(StorageEvents::PRE_SAVE, [$storageEventTests, 'eventPreSave']);
$dispatcher->addListener(StorageEvents::POST_SAVE, [$storageEventTests, 'eventPostSave']);
$dispatcher->addListener(StorageEvents::PRE_DELETE, [$storageEventTests, 'eventPreDelete']);
$dispatcher->addListener(StorageEvents::POST_DELETE, [$storageEventTests, 'eventPreDelete']);
}