/** * @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)); } }
protected function getProfile(EventManagerInterface $eventManager, $profile = null) { $profiles = $this->profiles; if (null === $profile) { $profile = $this->searchProfiles($eventManager->getIdentifiers()); } elseif (is_scalar($profile)) { if (!array_key_exists($profile, $profiles)) { throw new \Exception("Profile '{$profile}' not found"); } $profile = $profiles[$profile]; } $profile = array_merge(array('name' => 'Event Manager', 'identifiers' => array(), 'events' => array(), 'map' => array()), $profile); if (empty($profile['events'])) { $profile['events'] = $eventManager->getEvents(); } return $profile; }