Gc\Mvc\Factory\ModuleManagerFactory::createService PHP Method

createService() public method

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.
public createService ( Zend\ServiceManager\ServiceLocatorInterface $serviceLocator ) : Zend\ModuleManager\ModuleManager
$serviceLocator Zend\ServiceManager\ServiceLocatorInterface Service Manager
return Zend\ModuleManager\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;
    }