1
1
<?php
2
2
/**
3
- * Copyright 2014 Adobe
4
- * All Rights Reserved.
3
+ * Copyright 2014 Adobe
4
+ * All Rights Reserved.
5
5
*/
6
6
7
7
namespace Magento \Framework \Config \Reader ;
@@ -83,8 +83,10 @@ class Filesystem implements \Magento\Framework\Config\ReaderInterface
83
83
84
84
/**
85
85
* Name of an attribute that stands for data type of node values
86
+ *
87
+ * @var string
86
88
*/
87
- private const TYPE_ATTRIBUTE = ' xsi:type ' ;
89
+ protected $ _typeAttributeName ;
88
90
89
91
/**
90
92
* Constructor
@@ -97,6 +99,7 @@ class Filesystem implements \Magento\Framework\Config\ReaderInterface
97
99
* @param array $idAttributes
98
100
* @param string $domDocumentClass
99
101
* @param string $defaultScope
102
+ * @param string $typeAttributeName
100
103
*/
101
104
public function __construct (
102
105
\Magento \Framework \Config \FileResolverInterface $ fileResolver ,
@@ -106,7 +109,8 @@ public function __construct(
106
109
$ fileName ,
107
110
$ idAttributes = [],
108
111
$ domDocumentClass = \Magento \Framework \Config \Dom::class,
109
- $ defaultScope = 'global '
112
+ $ defaultScope = 'global ' ,
113
+ $ typeAttributeName = null ,
110
114
) {
111
115
$ this ->_fileResolver = $ fileResolver ;
112
116
$ this ->_converter = $ converter ;
@@ -118,6 +122,7 @@ public function __construct(
118
122
? $ schemaLocator ->getPerFileSchema () : null ;
119
123
$ this ->_domDocumentClass = $ domDocumentClass ;
120
124
$ this ->_defaultScope = $ defaultScope ;
125
+ $ this ->_typeAttributeName = $ typeAttributeName ;
121
126
}
122
127
123
128
/**
@@ -153,6 +158,9 @@ protected function _readFiles($fileList)
153
158
foreach ($ fileList as $ key => $ content ) {
154
159
try {
155
160
if (!$ configMerger ) {
161
+ if ($ this ->isDbSchemaFile ($ key )) {
162
+ $ this ->_typeAttributeName = 'xsi:type ' ;
163
+ }
156
164
$ configMerger = $ this ->_createConfigMerger ($ this ->_domDocumentClass , $ content );
157
165
} else {
158
166
$ configMerger ->merge ($ content );
@@ -176,6 +184,9 @@ protected function _readFiles($fileList)
176
184
$ configMerger = null ;
177
185
foreach ($ fileList as $ key => $ content ) {
178
186
if (!$ configMerger ) {
187
+ if ($ this ->isDbSchemaFile ($ key )) {
188
+ $ this ->_typeAttributeName = 'xsi:type ' ;
189
+ }
179
190
$ configMerger = $ this ->_createConfigMerger ($ this ->_domDocumentClass , $ content );
180
191
} else {
181
192
$ configMerger ->merge ($ content );
@@ -206,6 +217,7 @@ protected function _readFiles($fileList)
206
217
*
207
218
* @param string $mergerClass
208
219
* @param string $initialContents
220
+ * @param string $typeAttributeName
209
221
* @return \Magento\Framework\Config\Dom
210
222
* @throws \UnexpectedValueException
211
223
*/
@@ -215,7 +227,7 @@ protected function _createConfigMerger($mergerClass, $initialContents)
215
227
$ initialContents ,
216
228
$ this ->validationState ,
217
229
$ this ->_idAttributes ,
218
- self :: TYPE_ATTRIBUTE ,
230
+ $ this -> _typeAttributeName ,
219
231
$ this ->_perFileSchema
220
232
);
221
233
if (!$ result instanceof \Magento \Framework \Config \Dom) {
@@ -225,4 +237,16 @@ protected function _createConfigMerger($mergerClass, $initialContents)
225
237
}
226
238
return $ result ;
227
239
}
240
+
241
+ /**
242
+ * Check schema file, return true if it is db_schema.xml
243
+ *
244
+ * @param string $filePath
245
+ * @return bool
246
+ */
247
+ private function isDbSchemaFile (string $ filePath ): bool {
248
+ // Check only if "db_schema.xml" is at the very end of the path
249
+ $ pattern = '/db_schema\.xml$/ ' ;
250
+ return preg_match ($ pattern , $ filePath ) === 1 ;
251
+ }
228
252
}
0 commit comments