Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Dom.php
Go to the documentation of this file.
1 <?php
7 
10 
12 {
16  private $booleanUtils;
17 
21  private $argumentParser;
22 
26  private $argumentInterpreter;
27 
33  public function __construct(
34  InterpreterInterface $argumentInterpreter,
35  BooleanUtils $booleanUtils = null,
36  ArgumentParser $argumentParser = null
37  ) {
38  $this->argumentInterpreter = $argumentInterpreter;
39  $this->booleanUtils = $booleanUtils ?: new BooleanUtils();
40  $this->argumentParser = $argumentParser ?: new ArgumentParser();
41  }
42 
54  public function convert($config)
55  {
56  $output = [];
58  foreach ($config->documentElement->childNodes as $node) {
59  if ($node->nodeType != XML_ELEMENT_NODE) {
60  continue;
61  }
62  switch ($node->nodeName) {
63  case 'preference':
64  $output['preferences'][$node->attributes->getNamedItem(
65  'for'
66  )->nodeValue] = $node->attributes->getNamedItem(
67  'type'
68  )->nodeValue;
69  break;
70  case 'type':
71  case 'virtualType':
72  $typeData = [];
73  $typeNodeAttributes = $node->attributes;
74  $typeNodeShared = $typeNodeAttributes->getNamedItem('shared');
75  if ($typeNodeShared) {
76  $typeData['shared'] = $this->booleanUtils->toBoolean($typeNodeShared->nodeValue);
77  }
78  if ($node->nodeName == 'virtualType') {
79  $attributeType = $typeNodeAttributes->getNamedItem('type');
80  // attribute type is required for virtual type only in merged configuration
81  if ($attributeType) {
82  $typeData['type'] = $attributeType->nodeValue;
83  }
84  }
85  $typeArguments = [];
86  $typePlugins = [];
88  foreach ($node->childNodes as $typeChildNode) {
89  if ($typeChildNode->nodeType != XML_ELEMENT_NODE) {
90  continue;
91  }
92  switch ($typeChildNode->nodeName) {
93  case 'arguments':
95  foreach ($typeChildNode->childNodes as $argumentNode) {
96  if ($argumentNode->nodeType != XML_ELEMENT_NODE) {
97  continue;
98  }
99  $argumentName = $argumentNode->attributes->getNamedItem('name')->nodeValue;
100  $argumentData = $this->argumentParser->parse($argumentNode);
101  $typeArguments[$argumentName] = $this->argumentInterpreter->evaluate(
102  $argumentData
103  );
104  }
105  break;
106  case 'plugin':
107  $pluginAttributes = $typeChildNode->attributes;
108  $pluginDisabledNode = $pluginAttributes->getNamedItem('disabled');
109  $pluginSortOrderNode = $pluginAttributes->getNamedItem('sortOrder');
110  $pluginTypeNode = $pluginAttributes->getNamedItem('type');
111  $pluginData = [
112  'sortOrder' => $pluginSortOrderNode ? (int)$pluginSortOrderNode->nodeValue : 0,
113  ];
114  if ($pluginDisabledNode) {
115  $pluginData['disabled'] = $this->booleanUtils->toBoolean(
116  $pluginDisabledNode->nodeValue
117  );
118  }
119  if ($pluginTypeNode) {
120  $pluginData['instance'] = $pluginTypeNode->nodeValue;
121  }
122  $typePlugins[$pluginAttributes->getNamedItem('name')->nodeValue] = $pluginData;
123  break;
124  default:
125  throw new \Exception(
126  "Invalid application config. Unknown node: {$typeChildNode->nodeName}."
127  );
128  }
129  }
130 
131  $typeData['arguments'] = $typeArguments;
132  if (!empty($typePlugins)) {
133  $typeData['plugins'] = $typePlugins;
134  }
135  $output[$typeNodeAttributes->getNamedItem('name')->nodeValue] = $typeData;
136  break;
137  default:
138  throw new \Exception("Invalid application config. Unknown node: {$node->nodeName}.");
139  }
140  }
141 
142  return $output;
143  }
144 }
if(!defined( 'PHP_VERSION_ID')||!(PHP_VERSION_ID===70002||PHP_VERSION_ID===70004||PHP_VERSION_ID >=70006))
Definition: bootstrap.php:14
$config
Definition: fraud_order.php:17
__construct(InterpreterInterface $argumentInterpreter, BooleanUtils $booleanUtils=null, ArgumentParser $argumentParser=null)
Definition: Dom.php:33