@@ -30,13 +30,21 @@ public function __construct(\Magento\Setup\Module\Di\Compiler\Log\Log $log)
30
30
*/
31
31
public function collectEntities (array $ files )
32
32
{
33
+ $ virtualTypes = [];
33
34
$ output = [];
35
+ $ factoriesOutput = [];
34
36
foreach ($ files as $ file ) {
35
37
$ dom = new \DOMDocument ();
36
38
$ dom ->load ($ file );
37
39
$ xpath = new \DOMXPath ($ dom );
38
40
$ xpath ->registerNamespace ("php " , "http://php.net/xpath " );
39
41
$ xpath ->registerPhpFunctions ('preg_match ' );
42
+ $ virtualTypeQuery = "//virtualType/@name " ;
43
+
44
+ foreach ($ xpath ->query ($ virtualTypeQuery ) as $ virtualNode ) {
45
+ $ virtualTypes [] = $ virtualNode ->nodeValue ;
46
+ }
47
+
40
48
$ regex = '/^(.*) \\\(.*)Proxy$/ ' ;
41
49
$ query = "/config/preference[ php:functionString('preg_match', ' {$ regex }', @type) > 0]/@type | " .
42
50
"//argument[@xsi:type='object' and php:functionString('preg_match', ' {$ regex }', text()) > 0] | " .
@@ -46,9 +54,35 @@ public function collectEntities(array $files)
46
54
foreach ($ xpath ->query ($ query ) as $ node ) {
47
55
$ output [] = $ node ->nodeValue ;
48
56
}
57
+
58
+ $ factoriesOutput = array_merge ($ factoriesOutput , $ this ->scanNonVirtualFactories ($ virtualTypes , $ xpath ));
49
59
}
60
+
50
61
$ output = array_unique ($ output );
51
- return $ this ->_filterEntities ($ output );
62
+ $ factoriesOutput = array_unique ($ factoriesOutput );
63
+ return array_merge ($ this ->_filterEntities ($ output ), $ factoriesOutput );
64
+ }
65
+
66
+ /**
67
+ * Scan factories from all di.xml and retrieve non virtual one
68
+ *
69
+ * @param array $virtualTypes
70
+ * @param \DOMXPath $domXpath
71
+ * @return array
72
+ */
73
+ private function scanNonVirtualFactories (array $ virtualTypes , \DOMXPath $ domXpath )
74
+ {
75
+ $ output = [];
76
+ $ regex = '/^(.*)Factory$/ ' ;
77
+ $ query = "//argument[@xsi:type='object' and php:functionString('preg_match', ' {$ regex }', text()) > 0] | " .
78
+ "//item[@xsi:type='object' and php:functionString('preg_match', ' {$ regex }', text()) > 0] " ;
79
+ foreach ($ domXpath ->query ($ query ) as $ node ) {
80
+ if (!in_array ($ node ->nodeValue , $ virtualTypes )) {
81
+ $ output [] = $ node ->nodeValue ;
82
+ }
83
+ }
84
+
85
+ return $ output ;
52
86
}
53
87
54
88
/**
0 commit comments