41 private $moduleRegistry;
48 private $filesystemDriver;
64 $this->converter = $converter;
65 $this->parser = $parser;
67 $this->moduleRegistry = $moduleRegistry;
68 $this->filesystemDriver = $filesystemDriver;
78 public function load(array $exclude = [])
81 foreach ($this->getModuleConfigs() as list($file,
$contents)) {
84 }
catch (\
Magento\Framework\Exception\LocalizedException $e) {
85 throw new \Magento\Framework\Exception\LocalizedException(
87 'Invalid Document: %1%2 Error: %3',
88 [$file, PHP_EOL, $e->getMessage()]
94 $data = $this->converter->convert($this->parser->getDom());
96 if (!in_array(
$name, $exclude)) {
100 return $this->sortBySequence(
$result);
115 private function getModuleConfigs()
118 foreach ($modulePaths as $modulePath) {
119 $filePath = str_replace([
'\\',
'/'], DIRECTORY_SEPARATOR,
"$modulePath/etc/module.xml");
120 yield [$filePath, $this->filesystemDriver->fileGetContents($filePath)];
131 private function sortBySequence($origList)
135 foreach ($origList as $moduleName =>
$value) {
137 'name' => $moduleName,
138 'sequence' => $this->expandSequence($origList, $moduleName),
143 $total = count($expanded);
144 for (
$i = 0;
$i < $total - 1;
$i++) {
145 for ($j =
$i; $j < $total; $j++) {
146 if (in_array($expanded[$j][
'name'], $expanded[
$i][
'sequence'])) {
147 $temp = $expanded[
$i];
148 $expanded[
$i] = $expanded[$j];
149 $expanded[$j] = $temp;
155 foreach ($expanded as $pair) {
156 $result[$pair[
'name']] = $origList[$pair[
'name']];
171 private function expandSequence($list,
$name, $accumulated = [])
173 $accumulated[] =
$name;
175 foreach (
$result as $relatedName) {
176 if (in_array($relatedName, $accumulated)) {
177 throw new \Exception(
"Circular sequence reference from '{$name}' to '{$relatedName}'.");
179 if (!isset($list[$relatedName])) {
182 $relatedResult = $this->expandSequence($list, $relatedName, $accumulated);
__construct(Dom $converter, Parser $parser, ComponentRegistrarInterface $moduleRegistry, DriverInterface $filesystemDriver)
if(!isset($_GET['name'])) $name