Skip to content

Commit f6664a5

Browse files
committed
Use filesystem driver instead of dir reader to read module.xml files from vendor
1 parent f7e881c commit f6664a5

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

app/etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,11 @@
10761076
<argument name="overriddenBaseFiles" xsi:type="object">lessFileOverriddenBase</argument>
10771077
</arguments>
10781078
</type>
1079+
<type name="Magento\Framework\Module\ModuleList\Loader">
1080+
<arguments>
1081+
<argument name="filesystemDriver" xsi:type="object">Magento\Framework\Filesystem\Driver\File</argument>
1082+
</arguments>
1083+
</type>
10791084
<type name="Magento\Framework\Module\Setup\MigrationData">
10801085
<arguments>
10811086
<argument name="data" xsi:type="array">

lib/internal/Magento/Framework/Module/ModuleList/Loader.php

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\Module\Declaration\Converter\Dom;
1212
use Magento\Framework\Xml\Parser;
1313
use Magento\Framework\Module\Dir\ResolverInterface;
14-
use Magento\Framework\Filesystem\Directory\ReadInterface;
14+
use Magento\Framework\Filesystem\DriverInterface;
1515

1616
/**
1717
* Loader of module list information from the filesystem
@@ -46,21 +46,35 @@ class Loader
4646
*/
4747
private $dirResolver;
4848

49+
/**
50+
* Filesystem driver to allow reading of module.xml files which live outside of app/code
51+
*
52+
* @var DriverInterface
53+
*/
54+
private $filesystemDriver;
55+
4956
/**
5057
* Constructor
5158
*
5259
* @param Filesystem $filesystem
5360
* @param Dom $converter
5461
* @param Parser $parser
5562
* @param ResolverInterface $resolver
63+
* @param DriverInterface $filesystemDriver
5664
*/
57-
public function __construct(Filesystem $filesystem, Dom $converter, Parser $parser, ResolverInterface $resolver)
58-
{
65+
public function __construct(
66+
Filesystem $filesystem,
67+
Dom $converter,
68+
Parser $parser,
69+
ResolverInterface $resolver,
70+
DriverInterface $filesystemDriver
71+
) {
5972
$this->filesystem = $filesystem;
6073
$this->converter = $converter;
6174
$this->parser = $parser;
6275
$this->parser->initErrorHandler();
6376
$this->dirResolver = $resolver;
77+
$this->filesystemDriver = $filesystemDriver;
6478
}
6579

6680
/**
@@ -72,10 +86,7 @@ public function __construct(Filesystem $filesystem, Dom $converter, Parser $pars
7286
public function load()
7387
{
7488
$result = [];
75-
$dir = $this->filesystem->getDirectoryRead(DirectoryList::MODULES);
76-
foreach ($this->getModuleConfigPaths($dir) as $file) {
77-
$contents = $dir->readFile($file);
78-
89+
foreach ($this->getModuleConfigs() as $contents) {
7990
try {
8091
$this->parser->loadXML($contents);
8192
} catch (\Magento\Framework\Exception\LocalizedException $e) {
@@ -96,20 +107,23 @@ public function load()
96107
}
97108

98109
/**
99-
* Get an array containing the absolute file paths to all known module.xml files
110+
* Returns a traversable yielding content of all module.xml files
100111
*
101-
* @param ReadInterface $modulesDir
102-
* @return array
112+
* @return \Traversable
113+
*
114+
* @author Josh Di Fabio <joshdifabio@gmail.com>
103115
*/
104-
private function getModuleConfigPaths(ReadInterface $modulesDir)
116+
private function getModuleConfigs()
105117
{
106-
$moduleConfigPaths = $modulesDir->search('*/*/etc/module.xml');
118+
$modulesDir = $this->filesystem->getDirectoryRead(DirectoryList::MODULES);
119+
foreach ($modulesDir->search('*/*/etc/module.xml') as $filePath) {
120+
yield $modulesDir->readFile($filePath);
121+
}
107122

108123
foreach ($this->dirResolver->getModulePaths() as $modulePath) {
109-
$moduleConfigPaths[] = $modulesDir->getAbsolutePath("$modulePath/etc/modules.xml");
124+
$filePath = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, "$modulePath/etc/module.xml");
125+
yield $this->filesystemDriver->fileGetContents($filePath);
110126
}
111-
112-
return array_unique($moduleConfigPaths);
113127
}
114128

115129
/**

0 commit comments

Comments
 (0)