|
1 | 1 | <?php
|
| 2 | +declare(strict_types=1); |
| 3 | + |
2 | 4 | /**
|
3 | 5 | * Copyright © Magento, Inc. All rights reserved.
|
4 | 6 | * See COPYING.txt for license details.
|
@@ -42,42 +44,55 @@ public function collectEntities(array $files)
|
42 | 44 | $virtualTypeQuery = "//virtualType/@name";
|
43 | 45 |
|
44 | 46 | 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, '\\'); |
56 | 48 | }
|
57 | 49 |
|
58 |
| - $factoriesOutput = array_merge($factoriesOutput, $this->scanFactories($xpath)); |
| 50 | + $output[] = $this->scanProxies($xpath); |
| 51 | + $factoriesOutput[] = $this->scanFactories($xpath); |
59 | 52 | }
|
60 | 53 |
|
61 |
| - $output = array_unique($output); |
62 |
| - $factoriesOutput = array_unique($factoriesOutput); |
| 54 | + $output = array_unique(array_merge([], ...$output)); |
| 55 | + $factoriesOutput = array_unique(array_merge([], ...$factoriesOutput)); |
63 | 56 | $factoriesOutput = array_diff($factoriesOutput, $virtualTypes);
|
64 | 57 | return array_merge($this->_filterEntities($output), $factoriesOutput);
|
65 | 58 | }
|
66 | 59 |
|
67 | 60 | /**
|
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 |
69 | 83 | *
|
70 | 84 | * @param \DOMXPath $domXpath
|
71 | 85 | * @return array
|
72 | 86 | */
|
73 |
| - private function scanFactories(\DOMXPath $domXpath) |
| 87 | + private function scanFactories(\DOMXPath $domXpath): array |
74 | 88 | {
|
75 | 89 | $output = [];
|
76 |
| - $regex = '/^(.*)Factory$/'; |
| 90 | + $regex = '/^(\s+)?(.*)Factory(\s+)?$/'; |
77 | 91 | $query = "//argument[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0] |" .
|
78 | 92 | "//item[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0]";
|
| 93 | + |
79 | 94 | foreach ($domXpath->query($query) as $node) {
|
80 |
| - $output[] = $node->nodeValue; |
| 95 | + $output[] = ltrim(trim($node->nodeValue), '\\'); |
81 | 96 | }
|
82 | 97 |
|
83 | 98 | return $output;
|
|
0 commit comments