/** * 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(); }
/** * @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()); }
/** * @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 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')); }
/** * @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 onLoadModule(ModuleEvent $e) { $module = $e->getModule(); if (!$module instanceof DirectoryProviderInterface && !method_exists($module, 'getDir')) { return; } $moduleDirectory = $module->getDir(); if (!is_dir($moduleDirectory)) { return; } // Store the module path $moduleName = $e->getModuleName(); $this->paths[$moduleName] = array('path' => $moduleDirectory, 'template_path_stack' => null, 'default_template_path_stack' => null); // Check for especific module-dependant themes if ($module instanceof ConfigProviderInterface || is_callable(array($this, 'getConfig'))) { $config = $module->getConfig(); if ($config instanceof Traversable) { $config = ArrayUtils::iteratorToArray($config); } if (!is_array($config)) { throw new Exception\InvalidArgumentException(sprintf('Config being merged must be an array, ' . 'implement the Traversable interface, or be an ' . 'instance of Zend\\Config\\Config. %s given.', gettype($config))); } if (isset($config['theme_manager'])) { if (is_array($config['theme_manager'])) { if (isset($config['theme_manager']['template_path_stack'])) { $this->paths[$moduleName]['template_path_stack'] = $config['theme_manager']['template_path_stack']; } } } if (isset($config['view_manager'])) { if (is_array($config['view_manager'])) { if (isset($config['view_manager']['template_path_stack'])) { $this->paths[$moduleName]['default_template_path_stack'] = $config['view_manager']['template_path_stack']; } } } } }
/** * Merge the config for each module * * @param ModuleEvent $e * @return ConfigListener */ public function onLoadModule(ModuleEvent $e) { $module = $e->getModule(); if (!$module instanceof ConfigProviderInterface && !is_callable(array($module, 'getConfig'))) { return $this; } $config = $module->getConfig(); $this->addConfig($e->getModuleName(), $config); return $this; }
/** * Retrieve service manager configuration from module, and * configure the service manager. * * If the module does not implement a specific interface and does not * implement a specific method, does nothing. Also, if the return value * of that method is not a ServiceConfig object, or not an array or * Traversable that can seed one, does nothing. * * The interface and method name can be set by adding a new service manager * via the addServiceManager() method. * * @param ModuleEvent $e * @return void */ public function onLoadModule(ModuleEvent $e) { $module = $e->getModule(); foreach ($this->serviceManagers as $key => $sm) { if (!$module instanceof $sm['module_class_interface'] && !method_exists($module, $sm['module_class_method'])) { continue; } $config = $module->{$sm['module_class_method']}(); if ($config instanceof ServiceConfigInterface) { $config = $this->serviceConfigToArray($config); } if ($config instanceof Traversable) { $config = ArrayUtils::iteratorToArray($config); } if (!is_array($config)) { // If we do not have an array by this point, nothing left to do. continue; } // We are keeping track of which modules provided which configuration to which service managers. // The actual merging takes place later. Doing it this way will enable us to provide more powerful // debugging tools for showing which modules overrode what. $fullname = $e->getModuleName() . '::' . $sm['module_class_method'] . '()'; $this->serviceManagers[$key]['configuration'][$fullname] = $config; } }
/** * Retrieve service manager configuration from module, and * configure the service manager. * * If the module does not implement ServiceProviderInterface and does not * implement the "getServiceConfiguration()" method, does nothing. Also, * if the return value of that method is not a ServiceConfiguration object, * or not an array or Traversable that can seed one, does nothing. * * @param ModuleEvent $e * @return void */ public function onLoadModule(ModuleEvent $e) { $module = $e->getModule(); if (!$module instanceof ServiceProviderInterface && !method_exists($module, 'getServiceConfiguration') ) { return; } $config = $module->getServiceConfiguration(); if ($config instanceof ServiceConfiguration) { $this->mergeServiceConfiguration($config); return; } if ($config instanceof Traversable) { $config = ArrayUtils::iteratorToArray($config); } if (!is_array($config)) { // If we don't have an array by this point, nothing left to do. return; } $this->serviceConfig = ArrayUtils::merge($this->serviceConfig, $config); }
/** * Event callback for 'initServicesTrigger'. * * @param ModuleEvent $e * * @return $this */ public function getServicesTrigger(ModuleEvent $e) { $module = $e->getModule(); if (is_callable(array($module, 'getServiceConfig'))) { $services = $module->getServiceConfig(); if (is_array($services) && isset($services['factories'])) { $this->services[$e->getModuleName()] = $services['factories']; } } return $this; }
/** * @param \Zend\ModuleManager\ModuleEvent $e */ public function __invoke(ModuleEvent $e) { $module = $e->getModule(); echo get_class($module); exit; }
/** * @param ModuleEvent $e * @return void */ public function __invoke(ModuleEvent $e) { $module = $e->getModule(); if (!$module instanceof ThemeProviderInterface && !method_exists($module, 'initTheme')) { return; } $moduleManager = $e->getTarget(); $events = $moduleManager->getEventManager(); $sharedEvents = $events->getSharedManager(); $module_directory = $module->getDir(); $sharedEvents->attach('Zend\\Mvc\\Application', MvcEvent::EVENT_BOOTSTRAP, function ($e) use($module_directory) { $application = $e->getApplication(); $eventManager = $application->getEventManager(); $serviceManager = $application->getServiceManager(); $themeManager = $serviceManager->get('ThemeManager'); $theme = $themeManager->getTheme(); $theme_folder = $theme->getFolder(); $theme_path = $module_directory . '/themes/' . $theme_folder; if (!is_dir($theme_path)) { $theme = $themeManager->getDefaultTheme(); $theme_folder = $theme->getFolder(); if (!is_dir($theme_path)) { throw new MissingDefaultThemeException(); } } $theme_path = $module_directory . '/themes/' . $theme->getFolder(); // Views // Add the folder to the template resolver. $templatePathResolver = $serviceManager->get('Zend\\View\\Resolver\\TemplatePathStack'); $templatePathResolver->addPath($theme_path); // Layout if (file_exists($theme_path . '/layout.phtml')) { $templateMapResolver = $serviceManager->get('Zend\\View\\Resolver\\TemplateMapResolver'); $layout_name = $theme->getLayoutName(); if (!$templateMapResolver->has($layout_name)) { $templateMapResolver->add($layout_name, $theme_path . '/layout.phtml'); } } }); $sharedEvents->attach($module->getNamespace(), MvcEvent::EVENT_DISPATCH, function ($e) use($module_directory) { // Set the layout for this module if available $serviceManager = $e->getApplication()->getServiceManager(); $themeManager = $serviceManager->get('ThemeManager'); $theme = $themeManager->getTheme(); $theme_folder = $theme->getFolder(); $theme_path = $module_directory . '/themes/' . $theme_folder; if (!is_dir($theme_path)) { $theme = $themeManager->getDefaultTheme(); $theme_folder = $theme->getFolder(); if (!is_dir($theme_path)) { throw new MissingDefaultThemeException(); } } $layout_name = $theme->getLayoutName(); $templateMapResolver = $serviceManager->get('Zend\\View\\Resolver\\TemplateMapResolver'); if ($templateMapResolver->has($layout_name)) { $viewModel = $e->getViewModel(); $viewModel->setTemplate($layout_name); } }, 100); }