/** * @param EventManagerInterface $eventManager * @param StrategyPluginManager $listenerPluginManager * @param array $strategyConfig * @throws RuntimeException */ protected function attachWorkerListeners(EventManagerInterface $eventManager, StrategyPluginManager $listenerPluginManager, array $strategyConfig = []) { foreach ($strategyConfig as $strategy => $options) { // no options given, name stored as value if (is_numeric($strategy) && is_string($options)) { $strategy = $options; $options = []; } if (!is_string($strategy) || !is_array($options)) { continue; } $priority = null; if (isset($options['priority'])) { $priority = $options['priority']; unset($options['priority']); } $listener = $listenerPluginManager->get($strategy, $options); if (!is_null($priority)) { $eventManager->attachAggregate($listener, $priority); } else { $eventManager->attachAggregate($listener); } } if (!in_array(WorkerEvent::EVENT_BOOTSTRAP, $eventManager->getEvents())) { throw new RuntimeException(sprintf("No worker strategy has been registered to respond to the '%s' event.", WorkerEvent::EVENT_BOOTSTRAP)); } }
/** * Attach one or more listeners * * @param EventManagerInterface $events * @return DefaultListenerAggregate */ public function attach(EventManagerInterface $events) { $options = $this->getOptions(); $configListener = $this->getConfigListener(); $locatorRegistrationListener = new LocatorRegistrationListener($options); $moduleAutoloader = new ModuleAutoloader($options->getModulePaths()); $this->listeners[] = $events->attach('loadModules.pre', array($moduleAutoloader, 'register'), 1000); $this->listeners[] = $events->attach('loadModule.resolve', new ModuleResolverListener(), 1000); $this->listeners[] = $events->attach('loadModule', new AutoloaderListener($options), 2000); $this->listeners[] = $events->attach('loadModule', new InitTrigger($options), 1000); $this->listeners[] = $events->attach('loadModule', new OnBootstrapListener($options), 1000); $this->listeners[] = $events->attachAggregate($locatorRegistrationListener); $this->listeners[] = $events->attachAggregate($configListener); return $this; }
/** * Registers listeners if enabled. * * @return self */ public function init() { if ($this->options->isEnabled()) { if ($this->options->canFlushEarly()) { $this->eventManager->attachAggregate($this->serviceLocator->get('ZDT_FlushListener')); } if ($this->options->isStrict() && $this->report->hasErrors()) { throw new Exception\InvalidOptionException(implode(' ', $this->report->getErrors())); } $this->eventManager->attachAggregate($this->serviceLocator->get('ZDT_ProfileListener')); $this->registerVerbose()->registerToolbar(); if ($this->options->isStrict() && $this->report->hasErrors()) { throw new Exception\ProfilerException(implode(' ', $this->report->getErrors())); } } return $this; }
public function attach(ListenerAggregateInterface $listener) { $this->events->attachAggregate($listener); }
protected function loadEvent(EventManagerInterface $eventManager) { $eventManager->attachAggregate(new AuthorizationListenerAggregate()); }
/** * @param EventManagerInterface $eventManager */ protected function injectDefaultListeners(EventManagerInterface $eventManager) { $eventManager->attachAggregate(new Plugin\Message()); $eventManager->attachAggregate(new Feature\Executor()); $eventManager->attachAggregate(new Feature\Notifications()); }