Converter.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * Converter of attributes configuration from \DOMDocument to array
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Catalog\Model\Attribute\Config;
  9. class Converter implements \Magento\Framework\Config\ConverterInterface
  10. {
  11. /**
  12. * Convert dom node tree to array
  13. *
  14. * @param \DOMDocument $source
  15. * @return array
  16. */
  17. public function convert($source)
  18. {
  19. $result = [];
  20. /** @var DOMNode $groupNode */
  21. foreach ($source->documentElement->childNodes as $groupNode) {
  22. if ($groupNode->nodeType != XML_ELEMENT_NODE) {
  23. continue;
  24. }
  25. $groupName = $groupNode->attributes->getNamedItem('name')->nodeValue;
  26. /** @var DOMNode $groupAttributeNode */
  27. foreach ($groupNode->childNodes as $groupAttributeNode) {
  28. if ($groupAttributeNode->nodeType != XML_ELEMENT_NODE) {
  29. continue;
  30. }
  31. $groupAttributeName = $groupAttributeNode->attributes->getNamedItem('name')->nodeValue;
  32. $result[$groupName][] = $groupAttributeName;
  33. }
  34. }
  35. return $result;
  36. }
  37. }