/** * * @param \Zend\EventManager\Event $event */ public function onConfigMerge(ModuleEvent $event) { $config = $event->getConfigListener()->getMergedConfig(false); foreach ($config['sds']['doctrineExtensions']['manifest'] as $name => $manifestConfig) { if (!isset($manifestConfig['initalized']) || !$manifestConfig['initalized']) { $manifest = new Manifest($manifestConfig); $manifestConfig = $manifest->toArray(); $config['sds']['doctrineExtensions']['manifest'][$name] = $manifestConfig; //alias documentManager //add delegators $documentManagerConfig = $config; foreach (explode('.', $manifestConfig['document_manager']) as $key) { $documentManagerConfig = $documentManagerConfig[$key]; } $delegatorConfig = ['delegators' => [$manifestConfig['document_manager'] => ['doctrineExtensions.' . $name . '.documentManagerDelegatorFactory'], $documentManagerConfig['eventmanager'] => ['doctrineExtensions.' . $name . '.eventManagerDelegatorFactory'], $documentManagerConfig['configuration'] => ['doctrineExtensions.' . $name . '.configurationDelegatorFactory']]]; $config['service_manager'] = ArrayUtils::merge($config['service_manager'], $delegatorConfig); } } if (!isset($config['sds']['doctrineExtensions']['manifest']['default']) || !isset($config['sds']['doctrineExtensions']['manifest']['default']['extension_configs']['extension.dojo'])) { //remove dojo_src.default route if doctrineExtensions.dojo.default is not configured unset($config['router']['routes']['dojo.default']); } if (!isset($config['sds']['doctrineExtensions']['manifest']['default']) || !isset($config['sds']['doctrineExtensions']['manifest']['default']['extension_configs']['extension.rest'])) { //remove rest.default route if doctrineExtensions.rest.default is not configured unset($config['router']['routes']['rest.default']); } $event->getConfigListener()->setMergedConfig($config); }
/** * @param ModuleEvent $event * @throws Exception */ public function onMergeConfig(ModuleEvent $event) { // do not parse annotations if config cache is enabled. $config = $event->getConfigListener()->getMergedConfig(false); $annotationReader = AnnotationReaderFactory::factory($config['zf_annotation']); $parser = ClassParserFactory::factory($config, $event->getTarget()->getEventManager(), $annotationReader); $scanner = new DirectoryScanner(); $classesToParse = []; $modules = $event->getTarget()->getLoadedModules(); $modulesAllowedToScan = $config['zf_annotation']['scan_modules']; foreach ($modules as $module) { $parts = explode('\\', get_class($module)); $modName = array_shift($parts); if (!empty($modulesAllowedToScan) && !in_array($modName, $modulesAllowedToScan)) { continue; } $ref = new ReflectionClass($module); $dir = dirname($ref->getFileName()); foreach ($scanner->scan($dir) as $class) { $classesToParse[] = $class; } } $parsedConfig = $parser->parse($classesToParse); $event->getConfigListener()->setMergedConfig(array_replace_recursive($parsedConfig, $config)); }
/** * Creates and returns the module manager * * Instantiates the default module listeners, providing them configuration * from the "module_listener_options" key of the ApplicationConfig * service. Also sets the default config glob path. * * Module manager is instantiated and provided with an EventManager, to which * the default listener aggregate is attached. The ModuleEvent is also created * and attached to the module manager. * * @param ServiceLocatorInterface $serviceLocator * @return ModuleManager */ public function createService(ServiceLocatorInterface $serviceLocator) { if (!$serviceLocator->has('ServiceListener')) { $serviceLocator->setFactory('ServiceListener', 'HumusMvc\\Service\\ServiceListenerFactory'); } if (!$serviceLocator->has('Zf1MvcListener')) { $serviceLocator->setFactory('Zf1MvcListener', 'HumusMvc\\Service\\Zf1MvcListenerFactory'); } $configuration = $serviceLocator->get('ApplicationConfig'); $listenerOptions = new ListenerOptions($configuration['module_listener_options']); $defaultListeners = new DefaultListenerAggregate($listenerOptions); $serviceListener = $serviceLocator->get('ServiceListener'); $serviceListener->addServiceManager($serviceLocator, 'service_manager', 'Zend\\ModuleManager\\Feature\\ServiceProviderInterface', 'getServiceConfig'); $serviceListener->addServiceManager('ViewHelperManager', 'view_helpers', 'Zend\\ModuleManager\\Feature\\ViewHelperProviderInterface', 'getViewHelperConfig'); $serviceListener->addServiceManager('ActionHelperManager', 'action_helpers', 'HumusMvc\\ModuleManager\\Feature\\ActionHelperProviderInterface', 'getActionHelperConfig'); $events = $serviceLocator->get('EventManager'); $events->attach($defaultListeners); $events->attach($serviceListener); $sharedEvents = $events->getSharedManager(); $sharedEvents->attach('HumusMvc\\Application', 'bootstrap', new LocaleListener()); $moduleEvent = new ModuleEvent(); $moduleEvent->setParam('ServiceManager', $serviceLocator); $moduleManager = new ModuleManager($configuration['modules'], $events); $moduleManager->setEvent($moduleEvent); return $moduleManager; }
/** * @param ModuleEvent $e * @throws InvalidArgumentException */ public function extendRoutes(ModuleEvent $e) { $configListener = $e->getConfigListener(); $config = $configListener->getMergedConfig(false); // Allow extension of routes with overriding capability if (isset($config['router']['inheritance']) && is_array($config['router']['inheritance'])) { foreach ($config['router']['inheritance'] as $newRoute => $routeConfig) { // Not going to override any existing routes if (isset($config['router']['routes'][$newRoute])) { throw new InvalidArgumentException('Cannot extend route to existing route id.'); } // parent route must be provided if (!isset($routeConfig['extends'])) { throw new InvalidArgumentException('Parent route must be defined.'); } // parent route must exist if (!isset($config['router']['routes'][$routeConfig['extends']])) { throw new InvalidArgumentException('Parent route does not exist.'); } // If there is any configuration provided, it must be iterable if (isset($routeConfig['configuration']) && !is_array($routeConfig['configuration'])) { throw new InvalidArgumentException('Route overrides must be iterable.'); } // Copying the parent config and merging in the overrides $newRouteConfig = $config['router']['routes'][$routeConfig['extends']]; $newRouteConfig = ArrayUtils::merge($newRouteConfig, $routeConfig['configuration']); $config['router']['routes'][$newRoute] = $newRouteConfig; } // Removing this node so this isn't re-executed unset($config['router']['inheritance']); } // Pass the changed configuration back to the listener: $configListener->setMergedConfig($config); }
public function onMergeConfig(ModuleEvent $e) { $configListener = $e->getConfigListener(); $config = $configListener->getMergedConfig(false); // Modify the configuration; here, we'll add Oracle Custom DQL Functions: if (isset($config['doctrine_extensions']['oracle_doctrine_driver_config_key'])) { $configKey = $config['doctrine_extensions']['oracle_doctrine_driver_config_key']; //Get existing map (if any) to be merged with the module map if (isset($config['doctrine']['configuration'][$configKey])) { $existingMap = $config['doctrine']['configuration'][$configKey]; } else { $existingMap = array(); } $config['doctrine']['configuration'][$configKey] = array_merge_recursive($existingMap, DoctrineExtensionsUtilts::getOracleDQLFunctions()); } // Modify the configuration; here, we'll add MySQL Custom DQL Functions: if (isset($config['doctrine_extensions']['mysql_doctrine_driver_config_key'])) { $configKey = $config['doctrine_extensions']['mysql_doctrine_driver_config_key']; //Get existing map (if any) to be merged with the module map if (isset($config['doctrine']['configuration'][$configKey])) { $existingMap = $config['doctrine']['configuration'][$configKey]; } else { $existingMap = array(); } $config['doctrine']['configuration'][$configKey] = array_merge_recursive($existingMap, DoctrineExtensionsUtilts::getMysqlDQLFunctions()); } // Pass the changed configuration back to the listener: $configListener->setMergedConfig($config); }
/** * Creates and returns the module manager * * Instantiates the default module listeners, providing them configuration * from the "module_listener_options" key of the ApplicationConfig * service. Also sets the default config glob path. * * Module manager is instantiated and provided with an EventManager, to which * the default listener aggregate is attached. The ModuleEvent is also created * and attached to the module manager. * * @param ServiceLocatorInterface $serviceLocator * @return ModuleManager */ public function createService(ServiceLocatorInterface $serviceLocator) { if (!$serviceLocator->has('ServiceListener')) { $serviceLocator->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory'); } $configuration = $serviceLocator->get('ApplicationConfig'); $listenerOptions = new ListenerOptions($configuration['module_listener_options']); $defaultListeners = new DefaultListenerAggregate($listenerOptions); $serviceListener = $serviceLocator->get('ServiceListener'); $serviceListener->addServiceManager($serviceLocator, 'service_manager', 'Zend\\ModuleManager\\Feature\\ServiceProviderInterface', 'getServiceConfig'); $serviceListener->addServiceManager('ControllerLoader', 'controllers', 'Zend\\ModuleManager\\Feature\\ControllerProviderInterface', 'getControllerConfig'); $serviceListener->addServiceManager('ControllerPluginManager', 'controller_plugins', 'Zend\\ModuleManager\\Feature\\ControllerPluginProviderInterface', 'getControllerPluginConfig'); $serviceListener->addServiceManager('ViewHelperManager', 'view_helpers', 'Zend\\ModuleManager\\Feature\\ViewHelperProviderInterface', 'getViewHelperConfig'); $serviceListener->addServiceManager('ValidatorManager', 'validators', 'Zend\\ModuleManager\\Feature\\ValidatorProviderInterface', 'getValidatorConfig'); $serviceListener->addServiceManager('FilterManager', 'filters', 'Zend\\ModuleManager\\Feature\\FilterProviderInterface', 'getFilterConfig'); $serviceListener->addServiceManager('FormElementManager', 'form_elements', 'Zend\\ModuleManager\\Feature\\FormElementProviderInterface', 'getFormElementConfig'); $serviceListener->addServiceManager('RoutePluginManager', 'route_manager', 'Zend\\ModuleManager\\Feature\\RouteProviderInterface', 'getRouteConfig'); $serviceListener->addServiceManager('SerializerAdapterManager', 'serializers', 'Zend\\ModuleManager\\Feature\\SerializerProviderInterface', 'getSerializerConfig'); $serviceListener->addServiceManager('HydratorManager', 'hydrators', 'Zend\\ModuleManager\\Feature\\HydratorProviderInterface', 'getHydratorConfig'); $serviceListener->addServiceManager('InputFilterManager', 'input_filters', 'Zend\\ModuleManager\\Feature\\InputFilterProviderInterface', 'getInputFilterConfig'); $serviceListener->addServiceManager('LogProcessorManager', 'log_processors', 'Zend\\ModuleManager\\Feature\\LogProcessorProviderInterface', 'getLogProcessorConfig'); $serviceListener->addServiceManager('LogWriterManager', 'log_writers', 'Zend\\ModuleManager\\Feature\\LogWritersProviderInterface', 'getLogWriterConfig'); $events = $serviceLocator->get('EventManager'); $events->attach($defaultListeners); $events->attach($serviceListener); $moduleEvent = new ModuleEvent(); $moduleEvent->setParam('ServiceManager', $serviceLocator); $moduleManager = new ModuleManager($configuration['modules'], $events); $moduleManager->setEvent($moduleEvent); return $moduleManager; }
/** * Creates and returns the module manager * * Instantiates the default module listeners, providing them configuration * from the "module_listener_options" key of the ApplicationConfig * service. Also sets the default config glob path. * * Module manager is instantiated and provided with an EventManager, to which * the default listener aggregate is attached. The ModuleEvent is also created * and attached to the module manager. * * @param ServiceLocatorInterface $serviceLocator * @return ModuleManager */ public function createService(ServiceLocatorInterface $serviceLocator) { if (!$serviceLocator->has('ServiceListener')) { $serviceLocator->setFactory('ServiceListener', 'Console\\Service\\ServiceListenerFactory'); } $configuration = $serviceLocator->get('ApplicationConfig'); $listenerOptions = new ListenerOptions($configuration['module_listener_options']); $defaultListeners = new DefaultListenerAggregate($listenerOptions); $serviceListener = $serviceLocator->get('ServiceListener'); $serviceListener->addServiceManager($serviceLocator, 'service_manager', 'Zend\\ModuleManager\\Feature\\ServiceProviderInterface', 'getServiceConfig'); $serviceListener->addServiceManager('ValidatorManager', 'validators', 'Zend\\ModuleManager\\Feature\\ValidatorProviderInterface', 'getValidatorConfig'); $serviceListener->addServiceManager('FilterManager', 'filters', 'Zend\\ModuleManager\\Feature\\FilterProviderInterface', 'getFilterConfig'); $serviceListener->addServiceManager('SerializerAdapterManager', 'serializers', 'Zend\\ModuleManager\\Feature\\SerializerProviderInterface', 'getSerializerConfig'); $serviceListener->addServiceManager('SerializerAdapterManager', 'serializers', 'Zend\\ModuleManager\\Feature\\SerializerProviderInterface', 'getSerializerConfig'); $serviceListener->addServiceManager('HydratorManager', 'hydrators', 'Zend\\ModuleManager\\Feature\\HydratorProviderInterface', 'getHydratorConfig'); $serviceListener->addServiceManager('InputFilterManager', 'input_filters', 'Zend\\ModuleManager\\Feature\\InputFilterProviderInterface', 'getInputFilterConfig'); $events = $serviceLocator->get('EventManager'); $events->attach($defaultListeners); $events->attach($serviceListener); $moduleEvent = new ModuleEvent(); $moduleEvent->setParam('ServiceManager', $serviceLocator); $moduleManager = new ModuleManager($configuration['modules'], $events); $moduleManager->setEvent($moduleEvent); return $moduleManager; }
/** * loadModule * * Check each loaded module to see if it implements LocatorRegistered. If it * does, we add it to an internal array for later. * * @param ModuleEvent $e * @return void */ public function onLoadModule(ModuleEvent $e) { if (!$e->getModule() instanceof LocatorRegisteredInterface) { return; } $this->modules[] = $e->getModule(); }
public function onMergeConfig(\Zend\ModuleManager\ModuleEvent $event) { $configListener = $event->getConfigListener(); $config = $configListener->getMergedConfig(false); // echo '<pe>'; // print_r($config); // echo '</pre>'; }
/** * @param ModuleEvent $e * @eturn void */ public function __invoke(ModuleEvent $e) { $module = $e->getModule(); if (!$module instanceof InitProviderInterface && !method_exists($module, 'init')) { return; } $module->init($e->getTarget()); }
public function onMergeConfig(ModuleEvent $moduleEvent) { $configListener = $moduleEvent->getConfigListener(); $config = $configListener->getMergedConfig(false); // echo "<pre style='font-weight:bold'>"; // print_r($config['controllers']); // echo "</pre>"; }
/** * Called when the modules are loaded. * * @param ModuleEvent $event */ public function onLoadModulesPost(ModuleEvent $event) { /** @var ServiceManager $serviceManager */ $serviceManager = $event->getParam('ServiceManager'); /** @var EngineInterface $engine */ $engine = $serviceManager->get('phpab.engine'); $engine->start(); }
/** * @param ModuleEvent $e * @return void */ public function __invoke(ModuleEvent $e) { $module = $e->getModule(); if (!$module instanceof AutoloaderProviderInterface && !method_exists($module, 'getAutoloaderConfig')) { return; } $autoloaderConfig = $module->getAutoloaderConfig(); AutoloaderFactory::factory($autoloaderConfig); }
/** * @param ModuleEvent $e * @return object|false False if module class does not exist */ public function __invoke(ModuleEvent $e) { $moduleName = $e->getModuleName(); $class = $moduleName . '\\Module'; if (!class_exists($class)) { return false; } return new $class(); }
public function testModuleResolverListenerCanResolveModuleClasses() { $moduleResolver = new ModuleResolverListener(); $e = new ModuleEvent(); $e->setModuleName('ListenerTestModule'); $this->assertInstanceOf('ListenerTestModule\\Module', $moduleResolver($e)); $e->setModuleName('DoesNotExist'); $this->assertFalse($moduleResolver($e)); }
/** * @param ModuleEvent $e */ public function onPostLoadModules(ModuleEvent $e) { $configListener = $e->getConfigListener(); $config = $configListener->getMergedConfig(false); if (isset($config['doctrine']['configuration']['orm_default']['proxy_dir']) && isset($config['doctrine']['configuration']['orm_default']['proxy_namespace'])) { // We need to register here manualy. Please see http://www.doctrine-project.org/jira/browse/DDC-1698 ProxyAutoloader::register($config['doctrine']['configuration']['orm_default']['proxy_dir'], $config['doctrine']['configuration']['orm_default']['proxy_namespace']); } }
public function testInitRegistersPluginManager() { $event = new ModuleEvent(); $event->setParam('ServiceManager', $this->serviceLocator); $this->moduleManager->expects(self::any())->method('getEvent')->willReturn($event); $this->serviceLocator->setService('ServiceListener', $this->serviceListener); $this->serviceListener->expects(self::atLeastOnce())->method('addServiceManager'); $actual = $this->sut->init($this->moduleManager); self::assertNull($actual); }
public function onMergeConfig(ModuleEvent $e) { $configListener = $e->getConfigListener(); $config = $configListener->getMergedConfig(false); // Modify the configuration; here, we'll remove a specific key: if (isset($config['service_manager']['invokables']['VuFind\\Search'])) { unset($config['service_manager']['invokables']['VuFind\\Search']); } // Pass the changed configuration back to the listener: $configListener->setMergedConfig($config); }
/** * Pass self to the ModuleEvent object early so everyone has access. * * @param ModuleEvent $e * @return ConfigListener */ public function loadModulesPre(ModuleEvent $e) { if ($this->getOptions()->getConfigCacheEnabled()) { $this->getOptions()->setConfigCacheKey(implode('.', $e->getTarget()->getModules()) . '.' . $this->getOptions()->getConfigCacheKey()); if ($this->hasCachedConfig()) { $this->skipConfig = true; $this->setMergedConfig($this->getCachedConfig()); } } return parent::loadModulesPre($e); }
public function onMergeConfig(ModuleEvent $e) { $configListener = $e->getConfigListener(); $config = $configListener->getMergedConfig(false); // Make sure the router class is set to LocaleAwareTreeRouteStack if (!Console::isConsole()) { $config['router']['router_class'] = 'LocaleManager\\Router\\Http\\LocaleTreeRouteStack'; } // Pass the changed configuration back to the listener: $configListener->setMergedConfig($config); }
public function testShardDefaultsArePresentInMergedConfig() { $configListener = new ConfigListener(); $configListener->setMergedConfig(['zoop' => ['shard' => ['manifest' => ['default' => ['model_manager' => 'doctrine.odm.documentmanager.default', 'extension_configs' => ['extension.odmcore' => true, 'extension.serializer' => true]]]]], 'doctrine' => ['odm' => ['documentmanager' => ['default' => ['connection' => 'doctrine.odm.connection.default', 'configuration' => 'doctrine.odm.configuration.default', 'eventmanager' => 'doctrine.eventmanager.default']], 'configuration' => ['default' => ['class_metadata_factory_name' => 'Zoop\\Shard\\ODMCore\\ClassMetadataFactory', 'driver' => 'doctrine.driver.default']]], 'driver' => ['default' => []], 'eventmanager' => ['default' => []]]]); $event = new ModuleEvent(); $event->setConfigListener($configListener); $configMergeListener = new ConfigMergeListener(); $configMergeListener->onConfigMerge($event); $config = $configListener->getMergedConfig(false); $this->assertEquals('Zoop\\Shard\\Serializer\\Type\\Collection', $config['zoop']['shard']['manifest']['default']['service_manager_config']['invokables']['serializer.type.collection']); }
/** * @param ModuleEvent $e * @return void */ public function __invoke(ModuleEvent $e) { $module = $e->getModule(); if (!$module instanceof BootstrapListenerInterface && !method_exists($module, 'onBootstrap')) { return; } $moduleManager = $e->getTarget(); $events = $moduleManager->getEventManager(); $sharedEvents = $events->getSharedManager(); $sharedEvents->attach('Zend\\Mvc\\Application', MvcEvent::EVENT_BOOTSTRAP, array($module, 'onBootstrap')); }
/** * Override ZF\OAuth2\Service\OAuth2Server service * * If the ZF\OAuth2\Service\OAuth2Server is defined, and set to the * default, override it with the NamedOAuth2ServerFactory. * * @param ModuleEvent $e */ public function onMergeConfig(ModuleEvent $e) { $configListener = $e->getConfigListener(); $config = $configListener->getMergedConfig(false); $service = 'ZF\\OAuth2\\Service\\OAuth2Server'; $default = 'ZF\\OAuth2\\Factory\\OAuth2ServerFactory'; if (!isset($config['service_manager']['factories'][$service]) || $config['service_manager']['factories'][$service] !== $default) { return; } $config['service_manager']['factories'][$service] = __NAMESPACE__ . '\\Factory\\NamedOAuth2ServerFactory'; $configListener->setMergedConfig($config); }
/** * @param \Zend\ModuleManager\ModuleEvent $e * * @throws Exception\MissingDependencyModuleException */ public function __invoke(ModuleEvent $e) { $module = $e->getModule(); if ($module instanceof DependencyIndicatorInterface || method_exists($module, 'getModuleDependencies')) { $dependencies = $module->getModuleDependencies(); foreach ($dependencies as $dependencyModule) { if (!isset($this->loaded[$dependencyModule])) { throw new Exception\MissingDependencyModuleException(sprintf('Module "%s" depends on module "%s", which was not initialized before it', $e->getModuleName(), $dependencyModule)); } } } $this->loaded[$e->getModuleName()] = true; }
/** * @param ModuleEvent $e * @return void */ public function __invoke(ModuleEvent $e) { $module = $e->getModule(); if (!$module instanceof BootstrapListenerInterface && !method_exists($module, 'onBootstrap') ) { return; } $moduleManager = $e->getTarget(); $events = $moduleManager->events(); $sharedEvents = $events->getSharedManager(); $sharedEvents->attach('application', 'bootstrap', array($module, 'onBootstrap')); }
public function onLoadModules(ModuleEvent $event) { // /** @var ModuleManager $moduleManager */ // $moduleManager = $event->getTarget(); /** @var ServiceManager $serviceLocator */ $serviceLocator = $event->getParam('ServiceManager'); $serviceConfig = ArrayUtils::merge($this->getConfig(false)['service_manager'], $this->getServiceConfig()); $serviceConfig = new ServiceConfig($serviceConfig); $serviceConfig->configureServiceManager($serviceLocator); /** @var \Detail\VarCrypt\Listener\MultiEncryptorListener $encryptorListener */ $encryptorListener = $serviceLocator->get('Detail\\VarCrypt\\Listener\\MultiEncryptorListener'); $encryptorListener->onLoadModules($event); // $moduleManager->getEventManager()->attachAggregate($encryptorListener); }
/** * Init events * * @param \Zend\ModuleManager\ModuleEvent $e */ public function initEvents(ModuleEvent $e) { $model = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('ActionTracker\\Model\\ActionTrackerBase'); $actions = $model->getActivatedActions(); // bind all activated events if (count($actions)) { $eventManager = ActionTrackerEvent::getEventManager(); foreach ($actions as $action) { $eventManager->attach($action->name, function ($e) use($model, $action) { if ($model->getModuleInfo('ActionTracker')) { $model->logAction($action->action_id, $e->getParam('description'), $e->getParam('description_params')); } }); } } }
/** * Listen to ModuleEvent::EVENT_MERGE_CONFIG * * Looks for zf-versioning.url and router configuration; if both present, * injects the route prototype and adds a chain route to each route listed * in the zf-versioning.url array. * * @param ModuleEvent $e */ public function onMergeConfig(ModuleEvent $e) { $configListener = $e->getConfigListener(); if (!$configListener instanceof ConfigListener) { return; } $config = $configListener->getMergedConfig(false); // Check for config keys if (!isset($config['zf-versioning']) || !isset($config['router'])) { return; } // Do we need to inject a prototype? if (!isset($config['zf-versioning']['uri']) || !is_array($config['zf-versioning']['uri']) || empty($config['zf-versioning']['uri'])) { return; } // Override default version of 1 with user-specified config value, if available. if (isset($config['zf-versioning']['default_version'])) { $this->versionRouteOptions['defaults']['version'] = $config['zf-versioning']['default_version']; } // Pre-process route list to strip out duplicates (often a result of // specifying nested routes) $routes = $config['zf-versioning']['uri']; $filtered = []; foreach ($routes as $index => $route) { if (strstr($route, '/')) { $temp = explode('/', $route, 2); $route = array_shift($temp); } if (in_array($route, $filtered)) { continue; } $filtered[] = $route; } $routes = $filtered; // Inject chained routes foreach ($routes as $routeName) { if (!isset($config['router']['routes'][$routeName])) { continue; } if (false === strpos($config['router']['routes'][$routeName]['options']['route'], $this->versionRoutePrefix)) { $config['router']['routes'][$routeName]['options']['route'] = $this->versionRoutePrefix . $config['router']['routes'][$routeName]['options']['route']; } $config['router']['routes'][$routeName]['options'] = ArrayUtils::merge($config['router']['routes'][$routeName]['options'], $this->versionRouteOptions); } // Reset merged config $configListener->setMergedConfig($config); }
/** * * @param ModuleEvent $event */ public function onMergeConfig(ModuleEvent $event) { $config = $event->getConfigListener()->getMergedConfig(false); $modules = $event->getTarget()->getLoadedModules(); foreach ($modules as $module) { $ref = new ReflectionClass($module); $dir = dirname($ref->getFileName()) . '/view'; if (!is_dir($dir)) { continue; } if (!isset($config['view_manager']['template_path_stack'])) { $config['view_manager']['template_path_stack'] = array(); } $config['view_manager']['template_path_stack'][] = $dir; } $event->getConfigListener()->setMergedConfig($config); }
/** * Creates and returns the module manager * * Instantiates the default module listeners, providing them configuration * from the "module_listener_options" key of the ApplicationConfiguration * service. Also sets the default config glob path. * * Module manager is instantiated and provided with an EventManager, to which * the default listener aggregate is attached. The ModuleEvent is also created * and attached to the module manager. * * @param ServiceLocatorInterface $serviceLocator * @return ModuleManager */ public function createService(ServiceLocatorInterface $serviceLocator) { $configuration = $serviceLocator->get('ApplicationConfiguration'); $listenerOptions = new ListenerOptions($configuration['module_listener_options']); $defaultListeners = new DefaultListenerAggregate($listenerOptions); $serviceListener = new ServiceListener($serviceLocator, $this->defaultServiceConfiguration); $serviceListener->addServiceManager($serviceLocator, 'service_manager', 'Zend\\ModuleManager\\Feature\\ServiceProviderInterface', 'getServiceConfiguration'); $serviceListener->addServiceManager('ControllerLoader', 'controllers', 'Zend\\ModuleManager\\Feature\\ControllerProviderInterface', 'getControllerConfiguration'); $serviceListener->addServiceManager('ControllerPluginManager', 'controller_plugins', 'Zend\\ModuleManager\\Feature\\ControllerPluginProviderInterface', 'getControllerPluginConfiguration'); $serviceListener->addServiceManager('ViewHelperManager', 'view_helpers', 'Zend\\ModuleManager\\Feature\\ViewHelperProviderInterface', 'getViewHelperConfiguration'); $events = $serviceLocator->get('EventManager'); $events->attach($defaultListeners); $events->attach($serviceListener); $moduleEvent = new ModuleEvent(); $moduleEvent->setParam('ServiceManager', $serviceLocator); $moduleManager = new ModuleManager($configuration['modules'], $events); $moduleManager->setEvent($moduleEvent); return $moduleManager; }