11
11
use Magento \Framework \Module \Declaration \Converter \Dom ;
12
12
use Magento \Framework \Xml \Parser ;
13
13
use Magento \Framework \Module \Dir \ResolverInterface ;
14
- use Magento \Framework \Filesystem \Directory \ ReadInterface ;
14
+ use Magento \Framework \Filesystem \DriverInterface ;
15
15
16
16
/**
17
17
* Loader of module list information from the filesystem
@@ -46,21 +46,35 @@ class Loader
46
46
*/
47
47
private $ dirResolver ;
48
48
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
+
49
56
/**
50
57
* Constructor
51
58
*
52
59
* @param Filesystem $filesystem
53
60
* @param Dom $converter
54
61
* @param Parser $parser
55
62
* @param ResolverInterface $resolver
63
+ * @param DriverInterface $filesystemDriver
56
64
*/
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
+ ) {
59
72
$ this ->filesystem = $ filesystem ;
60
73
$ this ->converter = $ converter ;
61
74
$ this ->parser = $ parser ;
62
75
$ this ->parser ->initErrorHandler ();
63
76
$ this ->dirResolver = $ resolver ;
77
+ $ this ->filesystemDriver = $ filesystemDriver ;
64
78
}
65
79
66
80
/**
@@ -72,10 +86,7 @@ public function __construct(Filesystem $filesystem, Dom $converter, Parser $pars
72
86
public function load ()
73
87
{
74
88
$ 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 ) {
79
90
try {
80
91
$ this ->parser ->loadXML ($ contents );
81
92
} catch (\Magento \Framework \Exception \LocalizedException $ e ) {
@@ -96,20 +107,23 @@ public function load()
96
107
}
97
108
98
109
/**
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
100
111
*
101
- * @param ReadInterface $modulesDir
102
- * @return array
112
+ * @return \Traversable
113
+ *
114
+ * @author Josh Di Fabio <joshdifabio@gmail.com>
103
115
*/
104
- private function getModuleConfigPaths ( ReadInterface $ modulesDir )
116
+ private function getModuleConfigs ( )
105
117
{
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
+ }
107
122
108
123
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 );
110
126
}
111
-
112
- return array_unique ($ moduleConfigPaths );
113
127
}
114
128
115
129
/**
0 commit comments