/** * 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 Service Manager * * @return ModuleManager */ public function createService(ServiceLocatorInterface $serviceLocator) { $moduleCollection = new ModuleCollection(); $modules = $moduleCollection->getModules(); $array = array(); $autoloader = AutoloaderFactory::getRegisteredAutoloader(AutoloaderFactory::STANDARD_AUTOLOADER); foreach ($modules as $module) { $array[] = $module->getName(); $path = GC_APPLICATION_PATH . '/library/Modules/' . $module->getName(); if (file_exists($path) === false) { $path = GC_APPLICATION_PATH . '/extensions/Modules/' . $module->getName(); } $autoloader->registerNamespace($module->getName(), $path); } $autoloader->register(); $application = $serviceLocator->get('Application'); $configuration = $serviceLocator->get('ApplicationConfig'); $configuration['module_listener_options']['module_paths'] = array('./library/Modules', './extensions/Modules'); $listenerOptions = new Listener\ListenerOptions($configuration['module_listener_options']); $defaultListeners = new Listener\DefaultListenerAggregate($listenerOptions); $serviceListener = new Listener\ServiceListener($serviceLocator); $this->prepareServices($serviceListener, $serviceLocator); $moduleManager = new ModuleManager($array, $application->getEventManager()); $moduleManager->getEventManager()->attachAggregate($defaultListeners); $moduleManager->getEventManager()->attachAggregate($serviceListener); $moduleManager->loadModules(); $config = $moduleManager->getEvent()->getConfigListener()->getMergedConfig(false); $this->prepareConfig($serviceLocator, $config); foreach ($moduleManager->getLoadedModules() as $module) { if (method_exists($module, 'onBootstrap')) { $module->onBootstrap($application->getMvcEvent()); } } return $moduleManager; }
/** * Init Module form * * @return void */ public function init() { $this->setAttribute('class', 'relative'); $fileInfo = new Info(); $modulesInfos = array(); $options = array('' => 'Select an option'); foreach ($this->getServiceLocator()->get('ModulesList') as $path => $dir) { $options[$dir] = $dir; $configFile = $path . '/module.info'; if ($fileInfo->fromFile($configFile) === true) { $modulesInfos[$dir] = $fileInfo->render(); } } $collection = new ModuleCollection(); $modules = $collection->getModules(); foreach ($modules as $module) { if (in_array($module->getName(), $options)) { unset($options[$module->getName()]); unset($modulesInfos[$module->getName()]); } } $module = new Element\Select('module'); $module->setLabel('Module')->setLabelAttributes(array('class' => 'required')); $module->setAttribute('id', 'module')->setAttribute('class', 'form-control')->setAttribute('modules_info', $modulesInfos)->setValueOptions($options); $this->add($module); $inputFilterFactory = new InputFilterFactory(); $inputFilter = $inputFilterFactory->createInputFilter(array('module' => array('name' => 'module', 'required' => true, 'validators' => array(array('name' => 'not_empty'))))); $this->setInputFilter($inputFilter); }
/** * List all modules * * @return \Zend\View\Model\ViewModel */ public function indexAction() { $collection = new ModuleCollection(); $filter = new Filter\Word\CamelCaseToSeparator(); $filter->setSeparator('-'); $filterChain = new Filter\FilterChain(); $filterChain->attach($filter)->attach(new Filter\StringToLower()); foreach ($collection->getModules() as $module) { $module->setData('route', $filterChain->filter($module->getName())); } return array('modules' => $collection->getModules()); }