예제 #1
0
파일: Reader.php 프로젝트: opexsw/magento2
 /**
  * Read configuration scope
  *
  * @return array
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function read()
 {
     $fileList = [];
     foreach ($this->_scopePriorityScheme as $scope) {
         $directories = $this->_fileResolver->get($this->_fileName, $scope);
         foreach ($directories as $key => $directory) {
             $fileList[$key] = $directory;
         }
     }
     if (!count($fileList)) {
         return [];
     }
     /** @var \Magento\Framework\Config\Dom $domDocument */
     $domDocument = null;
     foreach ($fileList as $file) {
         try {
             if ($domDocument === null) {
                 $class = $this->_domDocumentClass;
                 $domDocument = new $class($file, [], null, $this->_schemaFile);
             } else {
                 $domDocument->merge($file);
             }
         } catch (\Magento\Framework\Config\Dom\ValidationException $e) {
             throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase("Invalid XML in file %1:\n%2", [$file, $e->getMessage()]));
         }
     }
     $output = [];
     if ($domDocument) {
         $output = $this->_converter->convert($domDocument->getDom());
     }
     return $output;
 }
예제 #2
0
 /**
  * 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->_isValidated) {
         $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;
 }
예제 #3
0
 /**
  * Load configuration scope
  *
  * @param string|null $scope
  * @return array
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function read($scope = null)
 {
     return $this->converter->convert($this->domMerger->getDom());
 }