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 
10 
15 {
21  private $booleanUtils;
22 
28  private $defaultValueProvider;
29 
36  public function __construct(BooleanUtils $booleanUtils, DefaultValueProvider $defaultValueProvider)
37  {
38  $this->booleanUtils = $booleanUtils;
39  $this->defaultValueProvider = $defaultValueProvider;
40  }
41 
45  public function convert($source)
46  {
47  $result = [];
49  foreach ($source->getElementsByTagName('publisher') as $publisherConfig) {
50  $topic = $this->getAttributeValue($publisherConfig, 'topic');
51 
52  $connections = [];
54  foreach ($publisherConfig->childNodes as $connectionConfig) {
55  if ($connectionConfig->nodeName != 'connection' || $connectionConfig->nodeType != XML_ELEMENT_NODE) {
56  continue;
57  }
58  $connectionName = $this->getAttributeValue($connectionConfig, 'name');
59  if (!$connectionName) {
60  throw new \InvalidArgumentException('Connection name is missing');
61  }
62  $exchangeName = $this->getAttributeValue(
63  $connectionConfig,
64  'exchange',
65  $this->defaultValueProvider->getExchange()
66  );
67  $isDisabled = $this->getAttributeValue($connectionConfig, 'disabled', false);
68  $connections[$connectionName] = [
69  'name' => $connectionName,
70  'exchange' => $exchangeName,
71  'disabled' => $this->booleanUtils->toBoolean($isDisabled),
72  ];
73  }
74  $isDisabled = $this->getAttributeValue($publisherConfig, 'disabled', false);
75  $result[$topic] = [
76  'topic' => $topic,
77  'disabled' => $this->booleanUtils->toBoolean($isDisabled),
78  'connections' => $connections,
79 
80  ];
81  }
82  return $result;
83  }
84 
93  private function getAttributeValue(\DOMNode $node, $attributeName, $default = null)
94  {
95  $item = $node->attributes->getNamedItem($attributeName);
96  return $item ? $item->nodeValue : $default;
97  }
98 }
$source
Definition: source.php:23
__construct(BooleanUtils $booleanUtils, DefaultValueProvider $defaultValueProvider)
Definition: Converter.php:36