Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Communication.php
Go to the documentation of this file.
1 <?php
7 
11 
16 {
20  private $converterUtils;
21 
25  public function __construct(ConverterUtils $converterUtils)
26  {
27  $this->converterUtils = $converterUtils;
28  }
29 
33  public function convert(\DOMNode $node, array $data = [])
34  {
35  if ($node->nodeType !== XML_ELEMENT_NODE) {
36  return [];
37  }
38  return $this->toArray($node);
39  }
40 
47  private function toArray(\DOMNode $node)
48  {
49  $result = [
50  'name' => $this->converterUtils->getComponentName($node),
51  Dom::TYPE_ATTRIBUTE => 'array'
52  ];
53  if ($this->hasChildNodes($node)) {
55  foreach ($node->childNodes as $childNode) {
56  if ($childNode->nodeType === XML_ELEMENT_NODE) {
57  $childNodeName = $this->converterUtils->getComponentName($childNode);
58  $result['item'][$childNodeName] = [
59  'name' => $childNodeName,
60  Dom::TYPE_ATTRIBUTE => 'string',
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)
convert(\DOMNode $node, array $data=[])