Skip to content

Commit 2ddc6d7

Browse files
committed
Fix issue when Proxy class wasn't generate during di compile
1 parent 8af9d33 commit 2ddc6d7

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

setup/src/Magento/Setup/Module/Di/Code/Scanner/XmlScanner.php

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* Copyright © Magento, Inc. All rights reserved.
46
* See COPYING.txt for license details.
@@ -42,42 +44,55 @@ public function collectEntities(array $files)
4244
$virtualTypeQuery = "//virtualType/@name";
4345

4446
foreach ($xpath->query($virtualTypeQuery) as $virtualNode) {
45-
$virtualTypes[] = $virtualNode->nodeValue;
46-
}
47-
48-
$regex = '/^(.*)\\\(.*)Proxy$/';
49-
$query = "/config/preference[ php:functionString('preg_match', '{$regex}', @type) > 0]/@type | " .
50-
"//argument[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0] |" .
51-
"//item[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0] |" .
52-
"/config/virtualType[ php:functionString('preg_match', '{$regex}', @type) > 0]/@type";
53-
/** @var \DOMNode $node */
54-
foreach ($xpath->query($query) as $node) {
55-
$output[] = $node->nodeValue;
47+
$virtualTypes[] = ltrim($virtualNode->nodeValue, '\\');
5648
}
5749

58-
$factoriesOutput = array_merge($factoriesOutput, $this->scanFactories($xpath));
50+
$output[] = $this->scanProxies($xpath);
51+
$factoriesOutput[] = $this->scanFactories($xpath);
5952
}
6053

61-
$output = array_unique($output);
62-
$factoriesOutput = array_unique($factoriesOutput);
54+
$output = array_unique(array_merge([], ...$output));
55+
$factoriesOutput = array_unique(array_merge([], ...$factoriesOutput));
6356
$factoriesOutput = array_diff($factoriesOutput, $virtualTypes);
6457
return array_merge($this->_filterEntities($output), $factoriesOutput);
6558
}
6659

6760
/**
68-
* Scan factories from all di.xml and retrieve non virtual one
61+
* Scan factories from all di.xml
62+
*
63+
* @param \DOMXPath $xpath
64+
* @return array
65+
*/
66+
private function scanProxies(\DOMXPath $xpath): array
67+
{
68+
$result = [];
69+
$regex = '/^(\s+)?(.*)\\\(.*)Proxy(\s+)?$/';
70+
$query = "/config/preference[ php:functionString('preg_match', '{$regex}', @type) > 0]/@type | " .
71+
"//argument[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0] |" .
72+
"//item[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0] |" .
73+
"/config/virtualType[ php:functionString('preg_match', '{$regex}', @type) > 0]/@type";
74+
/** @var \DOMNode $node */
75+
foreach ($xpath->query($query) as $node) {
76+
$result[] = ltrim(trim($node->nodeValue), '\\');
77+
}
78+
return $result;
79+
}
80+
81+
/**
82+
* Scan factories from all di.xml and retrieve non-virtual one
6983
*
7084
* @param \DOMXPath $domXpath
7185
* @return array
7286
*/
73-
private function scanFactories(\DOMXPath $domXpath)
87+
private function scanFactories(\DOMXPath $domXpath): array
7488
{
7589
$output = [];
76-
$regex = '/^(.*)Factory$/';
90+
$regex = '/^(\s+)?(.*)Factory(\s+)?$/';
7791
$query = "//argument[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0] |" .
7892
"//item[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0]";
93+
7994
foreach ($domXpath->query($query) as $node) {
80-
$output[] = $node->nodeValue;
95+
$output[] = ltrim(trim($node->nodeValue), '\\');
8196
}
8297

8398
return $output;

0 commit comments

Comments
 (0)