123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- /**
- * Default configuration data reader. Reads configuration data from storage
- *
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\App\Config\Initial;
- class Reader
- {
- /**
- * File locator
- *
- * @var \Magento\Framework\Config\FileResolverInterface
- */
- protected $_fileResolver;
- /**
- * Config converter
- *
- * @var \Magento\Framework\Config\ConverterInterface
- */
- protected $_converter;
- /**
- * Config file name
- *
- * @var string
- */
- protected $_fileName;
- /**
- * Class of dom configuration document used for merge
- *
- * @var string
- */
- protected $_domDocumentClass;
- /**
- * Scope priority loading scheme
- *
- * @var array
- */
- protected $_scopePriorityScheme = ['global'];
- /**
- * Path to corresponding XSD file with validation rules for config
- *
- * @var string
- */
- protected $_schemaFile;
- /**
- * @param \Magento\Framework\Config\FileResolverInterface $fileResolver
- * @param \Magento\Framework\Config\ConverterInterface $converter
- * @param SchemaLocator $schemaLocator
- * @param \Magento\Framework\Config\DomFactory $domFactory
- * @param string $fileName
- * @param string $domDocumentClass
- */
- public function __construct(
- \Magento\Framework\Config\FileResolverInterface $fileResolver,
- \Magento\Framework\Config\ConverterInterface $converter,
- SchemaLocator $schemaLocator,
- \Magento\Framework\Config\DomFactory $domFactory,
- $fileName = 'config.xml'
- ) {
- $this->_schemaFile = $schemaLocator->getSchema();
- $this->_fileResolver = $fileResolver;
- $this->_converter = $converter;
- $this->domFactory = $domFactory;
- $this->_fileName = $fileName;
- }
- /**
- * 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) {
- $domDocument = $this->domFactory->createDom(['xml' => $file, 'schemaFile' => $this->_schemaFile]);
- } else {
- $domDocument->merge($file);
- }
- } catch (\Magento\Framework\Config\Dom\ValidationException $e) {
- throw new \Magento\Framework\Exception\LocalizedException(
- new \Magento\Framework\Phrase(
- 'The XML in file "%1" is invalid:' . "\n%2\nVerify the XML and try again.",
- [$file, $e->getMessage()]
- )
- );
- }
- }
- $output = [];
- if ($domDocument) {
- $output = $this->_converter->convert($domDocument->getDom());
- }
- return $output;
- }
- }
|