/** * Read configuration files * * @param array $fileList * @return array * @throws \Magento\Framework\Exception\LocalizedException */ protected function _readFiles($fileList) { /** @var \Magento\Framework\Config\Dom $configMerger */ $configMerger = null; foreach ($fileList as $key => $content) { try { if (!$configMerger) { $configMerger = $this->_createConfigMerger($this->_domDocumentClass, $content); } else { $configMerger->merge($content); } } catch (\Magento\Framework\Config\Dom\ValidationException $e) { throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase("Invalid XML in file %1:\n%2", [$key, $e->getMessage()])); } } if ($this->validationState->isValidationRequired()) { $errors = []; if ($configMerger && !$configMerger->validate($this->_schemaFile, $errors)) { $message = "Invalid Document \n"; throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase($message . implode("\n", $errors))); } } $output = []; if ($configMerger) { $output = $this->_converter->convert($configMerger->getDom()); } return $output; }
/** * Validate self contents towards to specified schema * * @param string|null $schemaFilePath * @return array */ public function validate($schemaFilePath = null) { if (!$this->validationState->isValidationRequired()) { return []; } return $this->validateDomDocument($this->getDom(), $schemaFilePath); }
/** * Validate self contents towards to specified schema * * @param string $schemaFileName absolute path to schema file * @param array &$errors * @return bool */ public function validate($schemaFileName, &$errors = []) { if ($this->validationState->isValidationRequired()) { $errors = $this->validateDomDocument($this->dom, $schemaFileName, $this->errorFormat); return !count($errors); } return true; }