Skip to content

Commit f16c0c4

Browse files
author
Sergii Kovalenko
authored
Merge pull request #2159 from magento-trigger/MAGETWO-88054
- MAGETWO-88054 Move declarative setup from setup to framework - MAGETWO-88507 Allow Magento to generate factories from di.xml
2 parents 8478bdb + 63bf941 commit f16c0c4

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

app/code/Magento/Bundle/etc/db_schema.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@
4545
<constraint xsi:type="foreign" name="CAT_PRD_BNDL_OPT_VAL_OPT_ID_CAT_PRD_BNDL_OPT_OPT_ID"
4646
table="catalog_product_bundle_option_value" column="option_id"
4747
referenceTable="catalog_product_bundle_option" referenceColumn="option_id" onDelete="CASCADE"/>
48-
<constraint xsi:type="unique" name="CATALOG_PRODUCT_BUNDLE_OPTION_VALUE_OPTION_ID_STORE_ID">
49-
<column name="option_id"/>
50-
<column name="store_id"/>
51-
</constraint>
5248
<constraint xsi:type="unique" name="CAT_PRD_BNDL_OPT_VAL_OPT_ID_PARENT_PRD_ID_STORE_ID">
5349
<column name="option_id"/>
5450
<column name="parent_product_id"/>

lib/internal/Magento/Framework/Module/Dir/Reader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ public function getComposerJsonFiles()
105105
*/
106106
private function getFilesIterator($filename, $subDir = '')
107107
{
108-
#if (!isset($this->fileIterators[$subDir][$filename])) {
108+
if (!isset($this->fileIterators[$subDir][$filename])) {
109109
$this->fileIterators[$subDir][$filename] = $this->fileIteratorFactory->create(
110110
$this->getFiles($filename, $subDir)
111111
);
112-
#}
112+
}
113113
return $this->fileIterators[$subDir][$filename];
114114
}
115115

lib/internal/Magento/Framework/Setup/Patch/PatchApplier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
use Magento\Framework\Module\ModuleResource;
1111
use Magento\Framework\ObjectManagerInterface;
1212
use Magento\Framework\Phrase;
13-
use Magento\Framework\Setup\ModuleDataSetupInterface;
1413
use Magento\Framework\Setup\Exception;
14+
use Magento\Framework\Setup\ModuleDataSetupInterface;
1515

1616
/**
1717
* Apply patches per specific module

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,21 @@ public function __construct(\Magento\Setup\Module\Di\Compiler\Log\Log $log)
3030
*/
3131
public function collectEntities(array $files)
3232
{
33+
$virtualTypes = [];
3334
$output = [];
35+
$factoriesOutput = [];
3436
foreach ($files as $file) {
3537
$dom = new \DOMDocument();
3638
$dom->load($file);
3739
$xpath = new \DOMXPath($dom);
3840
$xpath->registerNamespace("php", "http://php.net/xpath");
3941
$xpath->registerPhpFunctions('preg_match');
42+
$virtualTypeQuery = "//virtualType/@name";
43+
44+
foreach ($xpath->query($virtualTypeQuery) as $virtualNode) {
45+
$virtualTypes[] = $virtualNode->nodeValue;
46+
}
47+
4048
$regex = '/^(.*)\\\(.*)Proxy$/';
4149
$query = "/config/preference[ php:functionString('preg_match', '{$regex}', @type) > 0]/@type | " .
4250
"//argument[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0] |" .
@@ -46,9 +54,33 @@ public function collectEntities(array $files)
4654
foreach ($xpath->query($query) as $node) {
4755
$output[] = $node->nodeValue;
4856
}
57+
58+
$factoriesOutput = array_merge($factoriesOutput, $this->scanFactories($xpath));
4959
}
60+
5061
$output = array_unique($output);
51-
return $this->_filterEntities($output);
62+
$factoriesOutput = array_unique($factoriesOutput);
63+
$factoriesOutput = array_diff($factoriesOutput, $virtualTypes);
64+
return array_merge($this->_filterEntities($output), $factoriesOutput);
65+
}
66+
67+
/**
68+
* Scan factories from all di.xml and retrieve non virtual one
69+
*
70+
* @param \DOMXPath $domXpath
71+
* @return array
72+
*/
73+
private function scanFactories(\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+
$output[] = $node->nodeValue;
81+
}
82+
83+
return $output;
5284
}
5385

5486
/**

0 commit comments

Comments
 (0)