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 
11 {
19  public function convert($source)
20  {
21  $output = [];
22  $xpath = new \DOMXPath($source);
23  $views = $xpath->evaluate('/config/view');
25  foreach ($views as $viewNode) {
26  $data = [];
27  $viewId = $this->getAttributeValue($viewNode, 'id');
28  $data['view_id'] = $viewId;
29  $data['action_class'] = $this->getAttributeValue($viewNode, 'class');
30  $data['group'] = $this->getAttributeValue($viewNode, 'group');
31  $data['subscriptions'] = [];
32 
34  foreach ($viewNode->childNodes as $childNode) {
35  if ($childNode->nodeType != XML_ELEMENT_NODE) {
36  continue;
37  }
38 
39  $data = $this->convertChild($childNode, $data);
40  }
41  $output[$viewId] = $data;
42  }
43  return $output;
44  }
45 
54  protected function getAttributeValue(\DOMNode $input, $attributeName, $default = null)
55  {
56  $node = $input->attributes->getNamedItem($attributeName);
57  return $node ? $node->nodeValue : $default;
58  }
59 
67  protected function convertChild(\DOMNode $childNode, $data)
68  {
69  switch ($childNode->nodeName) {
70  case 'subscriptions':
72  foreach ($childNode->childNodes as $subscription) {
73  if ($subscription->nodeType != XML_ELEMENT_NODE || $subscription->nodeName != 'table') {
74  continue;
75  }
76  $name = $this->getAttributeValue($subscription, 'name');
77  $column = $this->getAttributeValue($subscription, 'entity_column');
78  $subscriptionModel = $this->getAttributeValue($subscription, 'subscription_model');
79  if (!empty($subscriptionModel)
80  && !in_array(
81  SubscriptionInterface::class,
82  class_implements(ltrim($subscriptionModel, '\\'))
83  )
84  ) {
85  throw new \InvalidArgumentException(
86  'Subscription model must implement ' . SubscriptionInterface::class
87  );
88  }
89  $data['subscriptions'][$name] = [
90  'name' => $name,
91  'column' => $column,
92  'subscription_model' => $subscriptionModel
93  ];
94  }
95  break;
96  }
97  return $data;
98  }
99 }
$source
Definition: source.php:23
getAttributeValue(\DOMNode $input, $attributeName, $default=null)
Definition: Converter.php:54
if(!isset($_GET['name'])) $name
Definition: log.php:14