Creates an override graph for the given modules.

@param ModuleList $modules The modules to load.

@return static The created override graph.
428363
public static function forModules(ModuleList $modules)
    {
        $graph = new static($modules->getModuleNames());

        foreach ($modules as $module) {
            if (null === $module->getModuleFile()) {
                continue;
            }

            foreach ($module->getModuleFile()->getDependencies() as $dependency) {
                if ($graph->hasModuleName($dependency)) {
                    $graph->addDependency($module->getName(), $dependency);
                }
            }
        }

        // Do we have a root module?
        if (null === $modules->getRootModule()) {
            return $graph;
        }

        // Make sure we have numeric, ascending keys here
        $moduleOrder = array_values($modules->getRootModule()->getModuleFile()->getModuleOrder());

        // Each module overrides the previous one in the list
        for ($i = 1, $l = count($moduleOrder); $i < $l; ++$i) {
            $dependency = $moduleOrder[$i - 1];
            $moduleName = $moduleOrder[$i];

            if ($graph->hasModuleName($dependency)) {
                $graph->addDependency($moduleName, $dependency);
            }
        }

        return $graph;
    }
615615
public function parseModuleChains($modules)
    {
        $moduleArray = [];

        if (is_array($modules)) {
            foreach ($modules as $class => $moduleChain) {
                if (strstr($moduleChain, '&')) {
                    $moduleChain = explode('&', $moduleChain);
                } else {
                    $moduleChain = [$moduleChain];
                }
                $moduleArray[$class] = $moduleChain;
            }
        }

        return $moduleArray;
    }
998053
function moduleManager()
    {
        if (! $this->moduleManager ) {
            $mm = new ModuleManager;
            $mm->setTarget($this);
            $this->moduleManager = $mm;
        }

        return $this->moduleManager;
    }
538972
public AbstractGraph getModuleGraph(final String moduleId) {
        final ModuleHandler moduleHandler = new ModuleHandler(repoHandler);
        final DbModule module = moduleHandler.getModule(moduleId);
        final DbOrganization organization = moduleHandler.getOrganization(module);

        filters.setCorporateFilter(new CorporateFilter(organization));

        final AbstractGraph graph = new ModuleGraph();
        addModuleToGraph(module, graph, 0);

        return graph;
    }
382508
protected function getListModule()
    {
        $id = $this->getParam(0);

        if (!isset($id)) {
            $list = $this->module->getList();
            $this->limitArray($list);
            return $list;
        }

        $module = $this->module->get($id);

        if (empty($module)) {
            $this->errorAndExit($this->text('Unexpected result'));
        }

        return array($module);

    }
492835
protected function createRelationIndex(array $modules) : array
    {
        $index = [];

        foreach ($modules as $moduleName => $module) {
            if (! isset($module['relations'])) {
                $index[$moduleName] = [];
                continue;
            }

            if (! is_array($module['relations'])) {
                $index[$moduleName] = [];
                continue;
            }

            foreach ($module['relations'] as $relatedModule) {
                if (!empty($index[$relatedModule][$moduleName])) {
                    continue;
                }
                $index[$relatedModule][] = $moduleName;
            }
        }

        return $index;
    }
436740
private function coreModules(): Collection
    {
        return Collection::make(self::CORE_MODULES)
            ->map(static function (string $class, string $name): ModuleInterface {
                $module = app($class);

                $module->setName($name);

                return $module;
            });
    }
1157895
public static function initSubmodules($module)
    {
        $submodules = ArrayHelper::merge($module->modules, static::submodules($module));
        foreach ($submodules as $submoduleId => $submodule) {
            if (is_array($submodule)) $submodule = $module->getModule($submoduleId);
            if (empty($submodule)) continue;
            static::initSubmodules($submodule);
        }
    }
1274867
private SimpleDirectedGraph<ModuleModel, Edge> buildModuleDependencyGraph() {
		SimpleDirectedGraph<ModuleModel, Edge> g = buildExportGraph();

		// add import dependencies
		for (ModuleModel module : modules.values()) {
			for (ModuleModel imported : module.importedModules) {
				g.addEdge(module, imported);
			}
		}
		return g;
	}
62810
public function setModules(array $modules)
    {
        $this->modules = array();

        foreach ($modules as $module) {
            $this->addModule($module);
        }

        return $this;
    }
168180
public function sort()
    {
        if ($this->modules) {
            $modules = [];
            $sorter = new StringSort();

            foreach ($this->modules as $slug => $module) {
                $sorter->add($slug, array_intersect(array_keys($module->getAttribute('require')), array_keys($this->modules)));
            }

            foreach ($sorter->sort() as $slug) {
                $modules[$slug] = $this->modules[$slug];
            }

            // Override modules array
            $this->modules = $modules;
        }

        return $this;
    }
24096
public function setModule($module)
    {
        $layout = $this->getViewModel();
        $layout->setModule((string) $module);

        return $this;
    }
933901
protected function loadModuleList()
    {
        $modules = $this->getFileManager()->getFileList($this->pathToModules, false, '', false);

        $modulesToSort = array();
        if (is_array($modules)) {
            foreach ($modules as $moduleName) {
                if (!empty($moduleName) && !isset($modulesToSort[$moduleName])) {
                    $modulesToSort[$moduleName] = $this->getModuleConfig()->get($moduleName . '.order', $this->defaultModuleOrder);
                }
            }
        }

        array_multisort(array_values($modulesToSort), SORT_ASC, array_keys($modulesToSort), SORT_ASC, $modulesToSort);

        $this->moduleList = array_keys($modulesToSort);
    }
612612
public function setModules( $modules )
    {
        $saved = 0;
        $event = new ModulesEvent(
            ModulesEvent::EVENT_MODULES,
            $this,
            $modules
        );

        $event->setServiceLocator( $this->getServiceLocator() );

        /* @var $responses \Zend\EventManager\ResponseCollection */
        $responses = $this->getEventManager()
                          ->trigger( $event );

        foreach ( $responses as $response )
        {
            $saved += (int) $response;
        }

        return $saved;
    }
1197
private function addModuleRules()
	{
		// Load the routes from cache
		$moduleRoutes = array();
		$directories = glob(Yii::getPathOfAlias('application.modules') . '/*' , GLOB_ONLYDIR);

		foreach ($directories as $dir)
		{
			$routePath = $dir .DS. 'config' .DS. 'routes.php';
			if (file_exists($routePath))
			{
				$routes = require_once($routePath);
				// Unit tests are failing here for some reason
				if (!is_array($routes))
					continue;

				foreach ($routes as $k=>$v)
				$moduleRoutes[$k] = $v;
			}
		}

		return $moduleRoutes;
	}
810918
public function getModuleManager() {
		if ($this->moduleManager === null) {
			$this->moduleManager = new ModuleManager($this);
		}

		return $this->moduleManager;
	}
318737
function createGraph(modules, circular, config, options) {
	const g = graphviz.digraph('G');
	const nodes = {};
	const cyclicModules = circular.reduce((a, b) => a.concat(b), []);

	if (config.graphVizPath) {
		g.setGraphVizPath(config.graphVizPath);
	}

	Object.keys(modules).forEach((id) => {
		nodes[id] = nodes[id] || g.addNode(id);

		if (!modules[id].length) {
			setNodeColor(nodes[id], config.noDependencyColor);
		} else if (cyclicModules.indexOf(id) >= 0) {
			setNodeColor(nodes[id], config.cyclicNodeColor);
		}

		modules[id].forEach((depId) => {
			nodes[depId] = nodes[depId] || g.addNode(depId);

			if (!modules[depId]) {
				setNodeColor(nodes[depId], config.noDependencyColor);
			}

			g.addEdge(nodes[id], nodes[depId]);
		});
	});

	return new Promise((resolve, reject) => {
		g.output(options, resolve, (code, out, err) => {
			reject(new Error(err));
		});
	});
}