11<?php
22/**
3- * Filesystem configuration loader. Loads configuration from XML files, split by scopes
4- *
53 * Copyright © Magento, Inc. All rights reserved.
64 * See COPYING.txt for license details.
7- *
85 */
96
107namespace Magento \Framework \Config \Reader ;
118
129/**
10+ * Filesystem configuration loader. Loads configuration from XML files, split by scopes
11+ *
1312 * @SuppressWarnings(PHPMD.NumberOfChildren)
1413 * @api
1514 * @since 100.0.2
@@ -140,6 +139,7 @@ public function read($scope = null)
140139 * @param array $fileList
141140 * @return array
142141 * @throws \Magento\Framework\Exception\LocalizedException
142+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
143143 */
144144 protected function _readFiles ($ fileList )
145145 {
@@ -161,9 +161,27 @@ protected function _readFiles($fileList)
161161 );
162162 }
163163 }
164+
164165 if ($ this ->validationState ->isValidationRequired ()) {
165166 $ errors = [];
166167 if ($ configMerger && !$ configMerger ->validate ($ this ->_schemaFile , $ errors )) {
168+ // The merged XML is invalid, but each XML document is individually valid.
169+ // (If they had errors, we would have thrown an exception in the loop above.)
170+ // Let's work out which document is causing us a problem.
171+ $ configMerger = null ;
172+ foreach ($ fileList as $ key => $ content ) {
173+ if (!$ configMerger ) {
174+ $ configMerger = $ this ->_createConfigMerger ($ this ->_domDocumentClass , $ content );
175+ } else {
176+ $ configMerger ->merge ($ content );
177+ }
178+
179+ if (!$ configMerger ->validate ($ this ->_schemaFile )) {
180+ array_unshift ($ errors , "Error in merged XML after reading $ key " );
181+ break ;
182+ }
183+ }
184+
167185 $ message = "Invalid Document \n" ;
168186 throw new \Magento \Framework \Exception \LocalizedException (
169187 new \Magento \Framework \Phrase ($ message . implode ("\n" , $ errors ))
0 commit comments