/**
  * @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));
 }
 /**
  *
  * @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 $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);
 }
 /**
  * 
  * @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);
 }
Beispiel #6
0
 public function onMergeConfig(\Zend\ModuleManager\ModuleEvent $event)
 {
     $configListener = $event->getConfigListener();
     $config = $configListener->getMergedConfig(false);
     //        echo '<pe>';
     //        print_r($config);
     //        echo '</pre>';
 }
Beispiel #7
0
 public function onMergeConfig(ModuleEvent $moduleEvent)
 {
     $configListener = $moduleEvent->getConfigListener();
     $config = $configListener->getMergedConfig(false);
     // echo "<pre style='font-weight:bold'>";
     // print_r($config['controllers']);
     // echo "</pre>";
 }
Beispiel #8
0
 /**
  * @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 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);
 }
Beispiel #10
0
 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);
 }
 /**
  * @param ModuleEvent $e
  */
 public function onLoadModulesPost(ModuleEvent $e)
 {
     $appConfig = $this->serviceLocator->getServiceLocator()->get('ApplicationConfig');
     $extraConfig = array();
     if (isset($appConfig['framework']['app_config'])) {
         $extraConfig = Config::load($appConfig['framework']['app_config']);
     }
     // env config
     if (isset($appConfig['framework']['env_key'])) {
         $env = getenv($appConfig['framework']['env_key']);
         if ($env) {
             $filename = 'config/env/' . $env . '.yml';
             if (is_file($filename)) {
                 $envConfig = Config::load($filename);
                 $extraConfig = array_replace_recursive($extraConfig, $envConfig);
             }
         }
     }
     $config = ArrayUtils::merge($e->getConfigListener()->getMergedConfig(false), $extraConfig);
     $e->getConfigListener()->setMergedConfig($config);
 }
Beispiel #12
0
 /**
  * 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 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()) . '/language';
         if (!is_dir($dir)) {
             continue;
         }
         $iterator = new \DirectoryIterator($dir);
         foreach ($iterator as $file) {
             if ($file->isFile()) {
                 list($domain, $locale, $type) = explode('.', $file->getFilename());
                 if ($type === 'php') {
                     $type = 'phparray';
                 }
                 $config['translator']['translation_files'][] = array('type' => $type, 'filename' => $file->getPathname(), 'text_domain' => $domain, 'locale' => $locale);
             }
         }
     }
     $event->getConfigListener()->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);
         $dir1 = dirname($ref->getFileName()) . '/Entity';
         $dir2 = dirname($ref->getFileName()) . '/src/Entity';
         $dirs = array_filter([$dir1, $dir2], 'is_dir');
         if (count($dirs) == 0) {
             continue;
         }
         $dir = current($dirs);
         $parts = explode('\\', get_class($module));
         $moduleName = array_shift($parts);
         if (in_array($moduleName, $this->ignoreModules)) {
             continue;
         }
         $driverName = strtolower($moduleName) . '_entities';
         $config['doctrine']['driver']['orm_default']['drivers'][sprintf('%s\\Entity', $moduleName)] = $driverName;
         $config['doctrine']['driver'][$driverName] = array('class' => 'Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver', 'cache' => 'array', 'paths' => array($dir));
     }
     $event->getConfigListener()->setMergedConfig($config);
 }
 /**
  * 
  * @param ModuleEvent $event
  */
 public function onMergeConfig(ModuleEvent $event)
 {
     $config = $event->getConfigListener()->getMergedConfig(false);
     $resolvedControllers = $this->resolveControllers($config);
     $controllerInvokables = empty($config['controllers']['invokables']) ? [] : $config['controllers']['invokables'];
     $controllerFactories = empty($config['controllers']['factories']) ? [] : $config['controllers']['factories'];
     $controllers = array_merge($controllerInvokables, $controllerFactories);
     $injections = array();
     foreach ($controllers as $controller) {
         $ref = new ReflectionClass($controller);
         $fileScanner = new FileScanner($ref->getFileName());
         $classScanner = $fileScanner->getClass($controller);
         $methods = $classScanner->getMethods();
         $className = $classScanner->getName();
         $controllerName = $resolvedControllers[$className];
         foreach ($methods as $method) {
             $methodName = $method->getName();
             $actionName = preg_replace('/Action$/', '', $methodName);
             foreach ($method->getParameters() as $parameter) {
                 $parameterScanner = $method->getParameter($parameter);
                 $parameterName = $parameterScanner->getName();
                 $class = $parameterScanner->getClass();
                 if ($class) {
                     $objectManager = $this->detectObjectManager($class, $config['mvc']['doctrine_object_injector']);
                     if (null !== $objectManager) {
                         $injections[$controllerName][$actionName][$parameterName] = [$class, $objectManager, !$parameterScanner->isOptional()];
                     }
                 } else {
                     $injections[$controllerName][$actionName][$parameterName] = null;
                 }
             }
         }
     }
     $config['mvc']['doctrine_object_injector']['injections'] = $injections;
     $event->getConfigListener()->setMergedConfig($config);
 }
 /**
  * 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 \Zend\ModuleManager\ModuleEvent $event
  */
 public function onConfigMerge(ModuleEvent $event)
 {
     $config = $event->getConfigListener()->getMergedConfig(false);
     foreach ($config['zoop']['shard']['manifest'] as $name => $manifestConfig) {
         if (!isset($manifestConfig['initalized']) || !$manifestConfig['initalized']) {
             $modelManager = $manifestConfig['model_manager'];
             unset($manifestConfig['model_manager']);
             $manifest = new Manifest($manifestConfig);
             $manifestConfig = $manifest->toArray();
             $manifestConfig['model_manager'] = $modelManager;
             $config['zoop']['shard']['manifest'][$name] = $manifestConfig;
             $dmConfig =& $this->getSubConfig($config, $modelManager);
             //inject filter config
             $configurationConfig =& $this->getSubConfig($config, $dmConfig['configuration']);
             foreach ($manifest->getServiceManager()->get('extension.odmcore')->getFilters() as $filterName => $filterClass) {
                 $configurationConfig['filters'][$filterName] = $filterClass;
             }
             //inject models
             $driverConfig =& $this->getSubConfig($config, $configurationConfig['driver']);
             $count = 0;
             foreach ($manifest->getModels() as $namespace => $path) {
                 $driverConfig['drivers'][$namespace] = 'doctrine.driver.shard' . $name . $count;
                 $config['doctrine']['driver']['shard' . $name . $count] = ['class' => 'Doctrine\\ODM\\MongoDB\\Mapping\\Driver\\AnnotationDriver', 'paths' => [$path]];
                 $count++;
             }
             //inject subscribers
             $eventManagerConfig =& $this->getSubConfig($config, $dmConfig['eventmanager']);
             foreach ($manifest->getSubscribers() as $subscriber) {
                 $eventManagerConfig['subscribers'][] = 'shard.' . $name . '.' . $subscriber;
             }
             //make sure the Zoop/Shard/Core/ModuleManagerDelegator gets called
             $delegatorConfig = ['delegators' => [$modelManager => ['shard.' . $name . '.modelmanager.delegator.factory']]];
             if (isset($config['service_manager'])) {
                 $config['service_manager'] = ArrayUtils::merge($config['service_manager'], $delegatorConfig);
             } else {
                 $config['service_manager'] = $delegatorConfig;
             }
         }
     }
     $event->getConfigListener()->setMergedConfig($config);
 }
 /**
  * @param ModuleEvent $event
  * @return ConfigListener
  */
 public function onMergeConfig(ModuleEvent $event)
 {
     $configListener = $event->getConfigListener();
     $config = $configListener->getMergedConfig(false);
     $loadedModules = $event->getTarget()->getLoadedModules();
     $loadUthandoConfigs = isset($config['load_uthando_configs']) ? $config['load_uthando_configs'] : false;
     $uthandoConfig = [];
     if (false === $loadUthandoConfigs) {
         return $this;
     }
     // get the configurations from each module
     // must return an array to merge
     foreach ($loadedModules as $module) {
         if ($module instanceof ConfigInterface) {
             $moduleConfig = $module->getUthandoConfig();
             $uthandoConfig = ArrayUtils::merge($uthandoConfig, $moduleConfig);
         }
     }
     $config = ArrayUtils::merge($config, $uthandoConfig);
     // Pass the changed configuration back to the listener:
     $configListener->setMergedConfig($config);
     return $this;
 }
 /**
  * @param  ModuleEvent $e
  * @return void
  */
 public function __invoke(ModuleEvent $e)
 {
     // The modules have been loaded
     $target = $e->getTarget();
     if (!$target instanceof ModuleManagerInterface) {
         return;
     }
     $configListener = $e->getConfigListener();
     $config = $configListener->getMergedConfig(false);
     $modules = $target->getModules();
     $adapter = new Adapter($config['db']);
     $sql = new Sql($adapter);
     $select = $sql->select('modules');
     $select->columns(['name']);
     $select->where(['active' => true]);
     $select->order('order DESC');
     $statement = $sql->prepareStatementForSqlObject($select);
     $result = $statement->execute();
     if ($result instanceof ResultInterface && $result->isQueryResult() && $result->getAffectedRows()) {
         while ($current = $result->current()) {
             if (!in_array($current['name'], $modules)) {
                 $target->loadModule($current['name']);
                 $modules[] = $current['name'];
                 $module = $target->getModule($current['name']);
                 if ($module instanceof ConfigProviderInterface || is_callable([$module, 'getConfig'])) {
                     // Merge the config
                     $moduleConfig = $module->getConfig();
                     $config = ArrayUtils::merge($config, $moduleConfig);
                 }
             }
             $result->next();
         }
         $target->setModules($modules);
         $configListener->setMergedConfig($config);
     }
 }
 public function onMergeConfig(ModuleEvent $e)
 {
     $configListener = $e->getConfigListener();
     $config = $configListener->getMergedConfig(false);
     $mkAnnotationRouterConfig = $config['mk_annotation_router'];
     $controllers =& $config['controllers'];
     $reader = new AnnotationReader();
     // GENERATE PROJECT CONTROLLER CONFIG
     if ($mkAnnotationRouterConfig['generate_project_controller_config']) {
         $moduleDirs = $mkAnnotationRouterConfig['module_directory'];
         $moduleDirs = rtrim($moduleDirs, '/');
         if (empty($moduleDirs)) {
             $moduleDirs = getcwd() . '/module';
         }
         $moduleDirs .= '/*';
         $moduleDirs = glob($moduleDirs, GLOB_ONLYDIR);
         foreach ($moduleDirs as $moduleDir) {
             $moduleName = basename($moduleDir);
             $controllerFiles = glob("{$moduleDir}/src/{$moduleName}/Controller/*Controller.php");
             if ($controllerFiles && is_array($controllerFiles)) {
                 foreach ($controllerFiles as $controller) {
                     $className = preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($controller));
                     $controllerClass = "{$moduleName}\\Controller\\{$className}";
                     $config['controllers']['invokables'][$controllerClass] = $controllerClass;
                 }
             }
         }
     }
     // GENERATE ROUTES
     $routeToMergs = array();
     $methodRoutesToMerg = array();
     foreach ($controllers['invokables'] as $controllerAlias => $controllerClass) {
         $simpleControllerAlias = $controllerAlias;
         if ($controllerAlias == $controllerClass) {
             preg_match('/[a-zA-Z]+$/', $controllerClass, $matches);
             $simpleControllerAlias = $matches[0];
             $simpleControllerAlias = preg_replace('/Controller$/', '', "{$moduleName}{$simpleControllerAlias}");
         }
         $routeAnnotationClazz = new \ReflectionClass('ZendAnnotationRouter\\Annotation\\Route');
         $controllerClazz = new \ReflectionClass($controllerClass);
         /* @var $classRoute Route */
         $classRoutes = array();
         foreach ($reader->getClassAnnotations($controllerClazz) as $classRoute) {
             if ($routeAnnotationClazz->isInstance($classRoute)) {
                 $classRoute->name = empty($classRoute->name) ? $simpleControllerAlias : $classRoute->name;
                 $classRoute->defaults = array_merge(array('controller' => $controllerAlias, 'action' => 'index'), $classRoute->defaults);
                 $classRoute->route = empty($classRoute->route) ? $simpleControllerAlias : $classRoute->route;
                 $classRouteArr = $this->tranformRoute($classRoute);
                 if ($classRoute->extends) {
                     $classRouteArr = $this->extendsRoute($classRoute->extends, $classRouteArr);
                 }
                 $classRoutes[] = ['annotation' => $classRoute, 'route' => $classRouteArr];
                 $routeToMergs[] = $classRouteArr;
             }
         }
         do {
             foreach ($controllerClazz->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
                 if (preg_match('/Action$/', $method->getName())) {
                     /* @var $methodRoute Route */
                     foreach ($reader->getMethodAnnotations($method) as $methodRoute) {
                         if ($routeAnnotationClazz->isInstance($methodRoute)) {
                             $actionName = $this->methodToActionName($method->getName());
                             $methodRoute->name = empty($methodRoute->name) ? $actionName : $methodRoute->name;
                             $methodRoute->route = empty($methodRoute->route) ? $actionName : $methodRoute->route;
                             if (!empty($classRoutes) && !$methodRoute->extends) {
                                 $methodRoute->defaults = array_merge(array('action' => $actionName), $methodRoute->defaults);
                                 $methodRouteArr = $this->tranformRoute($methodRoute);
                                 foreach ($classRoutes as $cr) {
                                     $classRoute = $cr['annotation'];
                                     $extends = empty($classRoute->extends) ? $classRoute->name : $classRoute->extends . '/' . $classRoute->name;
                                     $methodRoutesToMerg[] = $this->extendsRoute($extends, $methodRouteArr);
                                 }
                             } else {
                                 $methodRoute->defaults = array_merge(array('controller' => $controllerAlias, 'action' => $actionName), $methodRoute->defaults);
                                 $methodRouteArr = $this->tranformRoute($methodRoute);
                                 if ($methodRoute->extends) {
                                     $methodRouteArr = $this->extendsRoute($methodRoute->extends, $methodRouteArr);
                                 }
                                 $methodRoutesToMerg[] = $methodRouteArr;
                             }
                         }
                     }
                 }
             }
             $controllerClazz = $controllerClazz->getParentClass();
         } while ($controllerClazz && $controllerClazz->getName() != 'Zend\\Mvc\\Controller\\AbstractActionController');
         $routeToMergs = array_merge($routeToMergs, $methodRoutesToMerg);
     }
     $finalAnnotationRoutes = call_user_func_array('array_replace_recursive', $routeToMergs);
     $config['router']['routes'] = ArrayUtils::merge($config['router']['routes'], $finalAnnotationRoutes);
     $configListener->setMergedConfig($config);
 }
Beispiel #21
0
 public function onMergeConfig(\Zend\ModuleManager\ModuleEvent $event)
 {
     $configListener = $event->getConfigListener();
     $config = $configListener->getMergedConfig(false);
 }
Beispiel #22
0
 /**
  * On all modules loaded
  *
  * @param \Zend\ModuleManager\ModuleEvent $event
  */
 public function onModulesLoaded(ModuleEvent $event)
 {
     $listener = $event->getConfigListener();
     $fakeLoad = clone $event;
     $listener->onLoadModule($fakeLoad->setModuleName('')->setModule(new DbModule($this->loadConfig())));
 }
 /**
  * Обработчик события загрузки всех модулей
  *
  * @param ModuleEvent $e
  */
 public function overrideAppConfigHandler(ModuleEvent $e)
 {
     $configListener = $e->getConfigListener();
     $baseAppConfig = $configListener->getMergedConfig(false);
     $overrideConfigs = $this->getOverrideConfigs();
     foreach ($overrideConfigs as $overrideConfig) {
         $baseAppConfig = ArrayUtils::merge($baseAppConfig, $overrideConfig);
     }
     $configListener->setMergedConfig($baseAppConfig);
 }
 /**
  * Use merged configuration to configure service manager
  *
  * If the merged configuration has a non-empty, array 'service_manager'
  * key, it will be passed to a ServiceManager Config object, and
  * used to configure the service manager.
  *
  * @param  ModuleEvent $e
  * @throws Exception\RuntimeException
  * @return void
  */
 public function onLoadModulesPost(ModuleEvent $e)
 {
     $configListener = $e->getConfigListener();
     $config = $configListener->getMergedConfig(false);
     foreach ($this->serviceManagers as $key => $sm) {
         $smConfig = $this->mergeServiceConfiguration($key, $sm, $config);
         if (!$sm['service_manager'] instanceof ServiceManager) {
             if (!$this->defaultServiceManager->has($sm['service_manager'])) {
                 throw new Exception\RuntimeException(sprintf('Could not find a valid ServiceManager for %s', $sm['service_manager']));
             }
             $instance = $this->defaultServiceManager->get($sm['service_manager']);
             if (!$instance instanceof ServiceManager) {
                 throw new Exception\RuntimeException(sprintf('Could not find a valid ServiceManager for %s', $sm['service_manager']));
             }
             $sm['service_manager'] = $instance;
         }
         $serviceConfig = new ServiceConfig($smConfig);
         // The service listener is meant to operate during bootstrap, and, as such,
         // needs to be able to override existing configuration.
         $allowOverride = $sm['service_manager']->getAllowOverride();
         $sm['service_manager']->setAllowOverride(true);
         $serviceConfig->configureServiceManager($sm['service_manager']);
         $sm['service_manager']->setAllowOverride($allowOverride);
     }
 }
Beispiel #25
0
    /**
     * Use merged configuration to configure service manager
     *
     * If the merged configuration has a non-empty, array 'service_manager' 
     * key, it will be passed to a ServiceManager Configuration object, and
     * used to configure the service manager.
     * 
     * @param  ModuleEvent $e 
     * @return void
     */
    public function onLoadModulesPost(ModuleEvent $e)
    {
        $configListener = $e->getConfigListener();
        $config         = $configListener->getMergedConfig(false);
        if (isset($config['service_manager'])
            && is_array($config['service_manager'])
            && !empty($config['service_manager'])
        ) {
            $this->serviceConfig = ArrayUtils::merge($this->serviceConfig, $config['service_manager']);
        }

        $this->configureServiceManager();
    }
Beispiel #26
0
 public function setOptions(ModuleEvent $e)
 {
     $config = $e->getConfigListener()->getMergedConfig(false);
     static::$options = $config['libra_locale'];
 }
 /**
  * Use merged configuration to configure service manager
  *
  * If the merged configuration has a non-empty, array 'service_manager'
  * key, it will be passed to a ServiceManager Config object, and
  * used to configure the service manager.
  *
  * @param  ModuleEvent $e
  * @throws Exception\RuntimeException
  * @return void
  */
 public function onLoadModulesPost(ModuleEvent $e)
 {
     $configListener = $e->getConfigListener();
     $config = $configListener->getMergedConfig(false);
     foreach ($this->serviceManagers as $key => $sm) {
         if (isset($config[$sm['config_key']]) && is_array($config[$sm['config_key']]) && !empty($config[$sm['config_key']])) {
             $this->serviceManagers[$key]['configuration']['merged_config'] = $config[$sm['config_key']];
         }
         // Merge all of the things!
         $smConfig = array();
         foreach ($this->serviceManagers[$key]['configuration'] as $configs) {
             if (isset($configs['configuration_classes'])) {
                 foreach ($configs['configuration_classes'] as $class) {
                     $configs = ArrayUtils::merge($configs, $this->serviceConfigToArray($class));
                 }
             }
             $smConfig = ArrayUtils::merge($smConfig, $configs);
         }
         if (!$sm['service_manager'] instanceof ServiceManager) {
             $instance = $this->defaultServiceManager->get($sm['service_manager']);
             if (!$instance instanceof ServiceManager) {
                 throw new Exception\RuntimeException(sprintf('Could not find a valid ServiceManager for %s', $sm['service_manager']));
             }
             $sm['service_manager'] = $instance;
         }
         $serviceConfig = new ServiceConfig($smConfig);
         $serviceConfig->configureServiceManager($sm['service_manager']);
     }
 }