Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Deps.php
Go to the documentation of this file.
1 <?php
7 
12 
16 class Deps implements ConverterInterface
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)) {
55  $i = 0;
57  foreach ($node->childNodes as $childNode) {
58  if ($childNode->nodeType === XML_ELEMENT_NODE) {
59  $result['item'][] = [
60  'name' => $i,
61  Dom::TYPE_ATTRIBUTE => 'string',
62  'value' => trim($childNode->nodeValue)
63  ];
64  $i++;
65  }
66  }
67  } else {
68  $result['item'][] = [
69  'name' => 0,
70  Dom::TYPE_ATTRIBUTE => 'string',
71  'value' => trim($node->nodeValue)
72  ];
73  }
74  return $result;
75  }
76 
83  private function hasChildNodes(\DOMNode $node)
84  {
85  if (!$node->hasChildNodes()) {
86  return false;
87  }
88 
89  foreach ($node->childNodes as $child) {
90  if ($child->nodeType == XML_ELEMENT_NODE) {
91  return true;
92  }
93  }
94 
95  return false;
96  }
97 }
convert(\DOMNode $node, array $data=[])
Definition: Deps.php:34
__construct(ConverterUtils $converterUtils)
Definition: Deps.php:26
$i
Definition: gallery.phtml:31