Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
AbstractXml Class Reference
Inheritance diagram for AbstractXml:
Config Config

Public Member Functions

 __construct ( $configFiles, \Magento\Framework\Config\DomFactory $domFactory)
 
 getSchemaFile ()
 
 getPerFileSchemaFile ()
 

Protected Member Functions

 _extractData (\DOMDocument $dom)
 
 _merge ($configFiles)
 
 _performValidate ($file=null)
 
 _getDomConfigModel ()
 
 _getInitialXml ()
 
 _getIdAttributes ()
 

Protected Attributes

 $_data
 
 $_domConfig = null
 
 $domFactory
 

Detailed Description

@api

Since
100.0.2

Definition at line 16 of file AbstractXml.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $configFiles,
\Magento\Framework\Config\DomFactory  $domFactory 
)

Instantiate with the list of files to merge

Parameters
array$configFiles
\Magento\Framework\Config\DomFactory$domFactory
Exceptions

Definition at line 43 of file AbstractXml.php.

46  {
47  $this->domFactory = $domFactory;
48  if (empty($configFiles)) {
49  throw new \InvalidArgumentException('There must be at least one configuration file specified.');
50  }
51  $this->_data = $this->_extractData($this->_merge($configFiles));
52  }

Member Function Documentation

◆ _extractData()

_extractData ( \DOMDocument  $dom)
abstractprotected

Extract configuration data from the DOM structure

Parameters
\DOMDocument$dom
Returns
array

◆ _getDomConfigModel()

_getDomConfigModel ( )
protected

Get Dom configuration model

Returns
\Magento\Framework\Config\Dom
Exceptions

Definition at line 131 of file AbstractXml.php.

132  {
133  if (null === $this->_domConfig) {
134  $this->_domConfig = $this->domFactory->createDom(
135  [
136  'xml' => $this->_getInitialXml(),
137  'idAttributes' => $this->_getIdAttributes(),
138  'schemaFile' => $this->getPerFileSchemaFile()
139  ]
140  );
141  }
142  return $this->_domConfig;
143  }

◆ _getIdAttributes()

_getIdAttributes ( )
abstractprotected

Get list of paths to identifiable nodes

Returns
array

◆ _getInitialXml()

_getInitialXml ( )
abstractprotected

Get XML-contents, initial for merging

Returns
string

◆ _merge()

_merge (   $configFiles)
protected

Merge the config XML-files

Parameters
array$configFiles
Returns
\DOMDocument
Exceptions

Definition at line 86 of file AbstractXml.php.

87  {
88  foreach ($configFiles as $key => $content) {
89  try {
90  $this->_getDomConfigModel()->merge($content);
91  } catch (\Magento\Framework\Config\Dom\ValidationException $e) {
92  throw new \Magento\Framework\Exception\LocalizedException(
93  new \Magento\Framework\Phrase(
94  'The XML in file "%1" is invalid:' . "\n%2\nVerify the XML and try again.",
95  [$key, $e->getMessage()]
96  )
97  );
98  }
99  }
100  $this->_performValidate();
101  return $this->_getDomConfigModel()->getDom();
102  }

◆ _performValidate()

_performValidate (   $file = null)
protected

Perform xml validation

Parameters
string$file
Returns
$this
Exceptions

Definition at line 111 of file AbstractXml.php.

112  {
113  $errors = [];
114  $this->_getDomConfigModel()->validate($this->getSchemaFile(), $errors);
115  if (!empty($errors)) {
116  $phrase = (null === $file)
117  ? new \Magento\Framework\Phrase('Invalid Document %1%2', [PHP_EOL, implode("\n", $errors)])
118  : new \Magento\Framework\Phrase('Invalid XML-file: %1%2%3', [$file, PHP_EOL, implode("\n", $errors)]);
119 
120  throw new \Magento\Framework\Exception\LocalizedException($phrase);
121  }
122  return $this;
123  }
$errors
Definition: overview.phtml:9

◆ getPerFileSchemaFile()

getPerFileSchemaFile ( )

Get absolute path to per-file XML-schema file

Returns
string

Definition at line 66 of file AbstractXml.php.

67  {
68  return null;
69  }

◆ getSchemaFile()

getSchemaFile ( )
abstract

Get absolute path to the XML-schema file

Returns
string

Field Documentation

◆ $_data

$_data
protected

Definition at line 23 of file AbstractXml.php.

◆ $_domConfig

$_domConfig = null
protected

Definition at line 29 of file AbstractXml.php.

◆ $domFactory

$domFactory
protected

Definition at line 34 of file AbstractXml.php.


The documentation for this class was generated from the following file: