Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Url.php
Go to the documentation of this file.
1 <?php
7 
12 
16 class Url 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 
40  return $this->toArray($node);
41  }
42 
49  public function toArray(\DOMNode $node)
50  {
51  $result[Converter::NAME_ATTRIBUTE_KEY] = $this->converterUtils->getComponentName($node);
52  if ($node->localName != 'param') {
54  }
55  if ($this->hasChildNodes($node)) {
56  $result = array_merge($result, $this->processChildNodes($node));
57  } else {
58  $nodeValue = trim($node->nodeValue);
59  if ($nodeValue !== '') {
60  $result['value'] = $nodeValue;
61  }
62  }
63 
64  if ($node->hasAttributes() && $node->nodeType === XML_ELEMENT_NODE) {
65  $result = array_merge($result, $this->processAttributes($node));
66  }
67  return $result;
68  }
69 
76  private function hasChildNodes(\DOMNode $node)
77  {
78  if ($node->hasChildNodes()) {
79  foreach ($node->childNodes as $childNode) {
80  if ($childNode->nodeType == XML_ELEMENT_NODE) {
81  return true;
82  }
83  }
84  }
85  return false;
86  }
87 
94  private function processAttributes(\DOMNode $node)
95  {
96  $attributes = [];
97  foreach ($node->attributes as $attribute) {
99  continue;
100  }
101  $attributes[$attribute->nodeName] = $attribute->value;
102  }
103 
104  return $attributes;
105  }
106 
113  private function processChildNodes(\DOMNode $node)
114  {
115  $result = [];
117  foreach ($node->childNodes as $childNode) {
118  if ($childNode->nodeType === XML_ELEMENT_NODE) {
119  $result['param'][$this->converterUtils->getComponentName($childNode)] = $this->toArray($childNode);
120  }
121  }
122  return $result;
123  }
124 }
convert(\DOMNode $node, array $data=[])
Definition: Url.php:34
$attributes
Definition: matrix.phtml:13
toArray(\DOMNode $node)
Definition: Url.php:49
__construct(ConverterUtils $converterUtils)
Definition: Url.php:26