Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Converter.php
Go to the documentation of this file.
1 <?php
9 
11 {
17  protected $_nodeMap = [];
18 
22  protected $_metadata = [];
23 
27  public function __construct(array $nodeMap = [])
28  {
29  $this->_nodeMap = $nodeMap;
30  }
31 
38  public function convert($source)
39  {
40  $output = [];
41  $xpath = new \DOMXPath($source);
42  $this->_metadata = [];
43 
45  foreach ($xpath->query(implode(' | ', $this->_nodeMap)) as $node) {
46  $output = array_merge($output, $this->_convertNode($node));
47  }
48  return ['data' => $output, 'metadata' => $this->_metadata];
49  }
50 
60  protected function _convertNode(\DOMNode $node, $path = '')
61  {
62  $output = [];
63  if ($node->nodeType == XML_ELEMENT_NODE) {
64  if ($node->hasAttributes()) {
65  $backendModel = $node->attributes->getNamedItem('backend_model');
66  if ($backendModel) {
67  $this->_metadata[$path] = ['backendModel' => $backendModel->nodeValue];
68  }
69  }
70  $nodeData = [];
72  foreach ($node->childNodes as $childNode) {
73  $childrenData = $this->_convertNode($childNode, ($path ? $path . '/' : '') . $childNode->nodeName);
74  if ($childrenData == null) {
75  continue;
76  }
77  if (is_array($childrenData)) {
78  $nodeData = array_merge($nodeData, $childrenData);
79  } else {
80  $nodeData = $childrenData;
81  }
82  }
83  if (is_array($nodeData) && empty($nodeData)) {
84  $nodeData = null;
85  }
86  $output[$node->nodeName] = $nodeData;
87  } elseif ($node->nodeType == XML_CDATA_SECTION_NODE || $node->nodeType == XML_TEXT_NODE && trim(
88  $node->nodeValue
89  ) != ''
90  ) {
91  return $node->nodeValue;
92  }
93 
94  return $output;
95  }
96 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$source
Definition: source.php:23