Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AdditionalClasses.php
Go to the documentation of this file.
1 <?php
7 
12 
17 {
21  private $converterUtils;
22 
26  public function __construct(ConverterUtils $converterUtils)
27  {
28  $this->converterUtils = $converterUtils;
29  }
30 
34  public function convert(\DOMNode $node, array $data = [])
35  {
36  if ($node->nodeType !== XML_ELEMENT_NODE) {
37  return [];
38  }
39  return $this->toArray($node);
40  }
41 
48  private function toArray(\DOMNode $node)
49  {
50  $result = [
51  'name' => $this->converterUtils->getComponentName($node),
52  Dom::TYPE_ATTRIBUTE => 'array'
53  ];
54  if ($this->hasChildNodes($node)) {
56  foreach ($node->childNodes as $childNode) {
57  if ($childNode->nodeType === XML_ELEMENT_NODE) {
58  $result['item'][$this->converterUtils->getComponentName($childNode)] = [
59  'name' => $childNode->getAttribute('name'),
60  Dom::TYPE_ATTRIBUTE => 'boolean',
61  'value' => trim($childNode->nodeValue)
62  ];
63  }
64  }
65  }
66  return $result;
67  }
68 
75  private function hasChildNodes(\DOMNode $node)
76  {
77  if (!$node->hasChildNodes()) {
78  return false;
79  }
80 
81  foreach ($node->childNodes as $child) {
82  if ($child->nodeType == XML_ELEMENT_NODE) {
83  return true;
84  }
85  }
86 
87  return false;
88  }
89 }
__construct(ConverterUtils $converterUtils)