Converter.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * Converter of customer address format configuration from \DOMDocument to array
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Customer\Model\Address\Config;
  9. class Converter implements \Magento\Framework\Config\ConverterInterface
  10. {
  11. /**
  12. * Convert customer address format configuration from dom node tree to array
  13. *
  14. * @param \DOMDocument $source
  15. * @return array
  16. */
  17. public function convert($source)
  18. {
  19. $output = [];
  20. /** @var \DOMNodeList $formats */
  21. $formats = $source->getElementsByTagName('format');
  22. /** @var \DOMNode $formatConfig */
  23. foreach ($formats as $formatConfig) {
  24. $formatCode = $formatConfig->attributes->getNamedItem('code')->nodeValue;
  25. $output[$formatCode] = [];
  26. for ($attributeIndex = 0; $attributeIndex < $formatConfig->attributes->length; $attributeIndex++) {
  27. $output[$formatCode][$formatConfig->attributes->item(
  28. $attributeIndex
  29. )->nodeName] = $formatConfig->attributes->item(
  30. $attributeIndex
  31. )->nodeValue;
  32. }
  33. }
  34. return $output;
  35. }
  36. }