Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Reader.php
Go to the documentation of this file.
1 <?php
11 
15 
21 class Reader extends \Magento\Framework\Config\Reader\Filesystem
22 {
28  protected $_idAttributes = [
29  '/config/system/tab' => 'id',
30  '/config/system/section' => 'id',
31  '/config/system/section(/group)+' => 'id',
32  '/config/system/section(/group)+/field' => 'id',
33  '/config/system/section(/group)+/field/depends/field' => 'id',
34  '/config/system/section(/group)+/field/options/option' => 'label',
35  ];
36 
40  protected $compiler;
41 
55  public function __construct(
56  \Magento\Framework\Config\FileResolverInterface $fileResolver,
57  Converter $converter,
58  \Magento\Config\Model\Config\SchemaLocator $schemaLocator,
59  \Magento\Framework\Config\ValidationStateInterface $validationState,
61  $fileName = 'system.xml',
62  $idAttributes = [],
63  $domDocumentClass = \Magento\Framework\Config\Dom::class,
64  $defaultScope = 'global'
65  ) {
66  $this->compiler = $compiler;
67  parent::__construct(
68  $fileResolver,
69  $converter,
70  $schemaLocator,
72  $fileName,
73  $idAttributes,
74  $domDocumentClass,
75  $defaultScope
76  );
77  }
78 
86  protected function _readFiles($fileList)
87  {
88 
90  $configMerger = null;
91  foreach ($fileList as $key => $content) {
92  try {
94  if (!$configMerger) {
95  $configMerger = $this->_createConfigMerger($this->_domDocumentClass, $content);
96  } else {
97  $configMerger->merge($content);
98  }
99  } catch (\Magento\Framework\Config\Dom\ValidationException $e) {
100  throw new LocalizedException(
101  new \Magento\Framework\Phrase(
102  'The XML in file "%1" is invalid:' . "\n%2\nVerify the XML and try again.",
103  [$key, $e->getMessage()]
104  )
105  );
106  }
107  }
108 
109  if ($this->validationState->isValidationRequired()) {
110  $errors = [];
111  if ($configMerger && !$configMerger->validate($this->_schemaFile, $errors)) {
112  $message = "Invalid Document \n";
113  throw new LocalizedException(
114  new \Magento\Framework\Phrase($message . implode("\n", $errors))
115  );
116  }
117  }
118 
119  $output = [];
120  if ($configMerger) {
121  $output = $this->_converter->convert($configMerger->getDom());
122  }
123 
124  return $output;
125  }
126 
134  protected function processingDocument($content)
135  {
136  $object = new DataObject();
137  $document = new \DOMDocument();
138  try {
139  $document->loadXML($content);
140  } catch (\Exception $e) {
141  throw new \Magento\Framework\Config\Dom\ValidationException($e->getMessage());
142  }
143  $this->compiler->compile($document->documentElement, $object, $object);
144 
145  return $document->saveXML();
146  }
147 }
__construct(\Magento\Framework\Config\FileResolverInterface $fileResolver, Converter $converter, \Magento\Config\Model\Config\SchemaLocator $schemaLocator, \Magento\Framework\Config\ValidationStateInterface $validationState, CompilerInterface $compiler, $fileName='system.xml', $idAttributes=[], $domDocumentClass=\Magento\Framework\Config\Dom::class, $defaultScope='global')
Definition: Reader.php:55
$fileList
Definition: export.php:13
$message
$fileName
Definition: translate.phtml:15
_createConfigMerger($mergerClass, $initialContents)
Definition: Filesystem.php:189
$errors
Definition: overview.phtml:9