11<?php
22/**
3- * Copyright 2014 Adobe
4- * All Rights Reserved.
3+ * Copyright 2014 Adobe
4+ * All Rights Reserved.
55 */
66
77namespace Magento \Framework \Config \Reader ;
@@ -83,8 +83,10 @@ class Filesystem implements \Magento\Framework\Config\ReaderInterface
8383
8484 /**
8585 * Name of an attribute that stands for data type of node values
86+ *
87+ * @var string
8688 */
87- private const TYPE_ATTRIBUTE = ' xsi:type ' ;
89+ protected $ _typeAttributeName ;
8890
8991 /**
9092 * Constructor
@@ -97,6 +99,7 @@ class Filesystem implements \Magento\Framework\Config\ReaderInterface
9799 * @param array $idAttributes
98100 * @param string $domDocumentClass
99101 * @param string $defaultScope
102+ * @param string $typeAttributeName
100103 */
101104 public function __construct (
102105 \Magento \Framework \Config \FileResolverInterface $ fileResolver ,
@@ -106,7 +109,8 @@ public function __construct(
106109 $ fileName ,
107110 $ idAttributes = [],
108111 $ domDocumentClass = \Magento \Framework \Config \Dom::class,
109- $ defaultScope = 'global '
112+ $ defaultScope = 'global ' ,
113+ $ typeAttributeName = null ,
110114 ) {
111115 $ this ->_fileResolver = $ fileResolver ;
112116 $ this ->_converter = $ converter ;
@@ -118,6 +122,7 @@ public function __construct(
118122 ? $ schemaLocator ->getPerFileSchema () : null ;
119123 $ this ->_domDocumentClass = $ domDocumentClass ;
120124 $ this ->_defaultScope = $ defaultScope ;
125+ $ this ->_typeAttributeName = $ typeAttributeName ;
121126 }
122127
123128 /**
@@ -153,6 +158,9 @@ protected function _readFiles($fileList)
153158 foreach ($ fileList as $ key => $ content ) {
154159 try {
155160 if (!$ configMerger ) {
161+ if ($ this ->isDbSchemaFile ($ key )) {
162+ $ this ->_typeAttributeName = 'xsi:type ' ;
163+ }
156164 $ configMerger = $ this ->_createConfigMerger ($ this ->_domDocumentClass , $ content );
157165 } else {
158166 $ configMerger ->merge ($ content );
@@ -176,6 +184,9 @@ protected function _readFiles($fileList)
176184 $ configMerger = null ;
177185 foreach ($ fileList as $ key => $ content ) {
178186 if (!$ configMerger ) {
187+ if ($ this ->isDbSchemaFile ($ key )) {
188+ $ this ->_typeAttributeName = 'xsi:type ' ;
189+ }
179190 $ configMerger = $ this ->_createConfigMerger ($ this ->_domDocumentClass , $ content );
180191 } else {
181192 $ configMerger ->merge ($ content );
@@ -206,6 +217,7 @@ protected function _readFiles($fileList)
206217 *
207218 * @param string $mergerClass
208219 * @param string $initialContents
220+ * @param string $typeAttributeName
209221 * @return \Magento\Framework\Config\Dom
210222 * @throws \UnexpectedValueException
211223 */
@@ -215,7 +227,7 @@ protected function _createConfigMerger($mergerClass, $initialContents)
215227 $ initialContents ,
216228 $ this ->validationState ,
217229 $ this ->_idAttributes ,
218- self :: TYPE_ATTRIBUTE ,
230+ $ this -> _typeAttributeName ,
219231 $ this ->_perFileSchema
220232 );
221233 if (!$ result instanceof \Magento \Framework \Config \Dom) {
@@ -225,4 +237,16 @@ protected function _createConfigMerger($mergerClass, $initialContents)
225237 }
226238 return $ result ;
227239 }
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+ }
228252}
0 commit comments