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
7 
9 
16 {
20  protected $extractorPool;
21 
26  {
27  $this->extractorPool = $extractorPool;
28  }
29 
37  public function convert($source)
38  {
39  $xpath = new \DOMXPath($source);
40  $output = [];
41  foreach ($xpath->evaluate('/view') as $typeNode) {
42  foreach ($typeNode->childNodes as $childNode) {
43  if ($childNode->nodeType != XML_ELEMENT_NODE) {
44  continue;
45  }
46  $result = $this->parseNodes($childNode);
47  $output = array_merge_recursive($output, $result);
48  }
49  }
50  return $output;
51  }
52 
59  protected function parseNodes($childNode)
60  {
61  $output = [];
62  switch ($childNode->nodeName) {
63  case 'vars':
64  $moduleName = $childNode->getAttribute('module');
65  $output[$childNode->tagName][$moduleName] = $this->parseVarElement($childNode);
66  break;
67  case 'exclude':
69  foreach ($childNode->getElementsByTagName('item') as $itemNode) {
70  $itemType = $itemNode->getAttribute('type');
71  $output[$childNode->tagName][$itemType][] = $itemNode->nodeValue;
72  }
73  break;
74  case 'media':
75  foreach ($childNode->childNodes as $mediaNode) {
76  if ($mediaNode instanceof \DOMElement) {
77  $mediaNodesArray =
78  $this->extractorPool->nodeProcessor($mediaNode->tagName)->process(
79  $mediaNode,
80  $childNode->tagName
81  );
82  $output = array_merge_recursive($output, $mediaNodesArray);
83  }
84  }
85  break;
86  }
87  return $output;
88  }
89 
96  protected function parseVarElement(\DOMElement $node)
97  {
98  $result = [];
99  for ($varNode = $node->firstChild; $varNode !== null; $varNode = $varNode->nextSibling) {
100  if ($varNode instanceof \DOMElement && $varNode->tagName == "var") {
101  $varName = $varNode->getAttribute('name');
102  $result[$varName] = $this->parseVarElement($varNode);
103  }
104  }
105  if (!count($result)) {
106  $result = (strtolower($node->nodeValue) !== 'true' && strtolower($node->nodeValue) !== 'false')
107  ? $node->nodeValue
108  : filter_var($node->nodeValue, FILTER_VALIDATE_BOOLEAN);
109  }
110  return $result;
111  }
112 }
__construct(TypeDataExtractorPool $extractorPool)
Definition: Converter.php:25
$source
Definition: source.php:23
parseVarElement(\DOMElement $node)
Definition: Converter.php:96