Converter.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Cache\Config;
  7. class Converter implements \Magento\Framework\Config\ConverterInterface
  8. {
  9. /**
  10. * Convert dom node tree to array
  11. *
  12. * @param \DOMDocument $source
  13. * @return array
  14. */
  15. public function convert($source)
  16. {
  17. $output = [];
  18. /** @var \DOMNodeList $types */
  19. $types = $source->getElementsByTagName('type');
  20. /** @var \DOMNode $type */
  21. foreach ($types as $type) {
  22. $typeConfig = [];
  23. foreach ($type->attributes as $attribute) {
  24. $typeConfig[$attribute->nodeName] = $attribute->nodeValue;
  25. }
  26. /** @var \DOMNode $childNode */
  27. foreach ($type->childNodes as $childNode) {
  28. if ($childNode->nodeType == XML_ELEMENT_NODE ||
  29. ($childNode->nodeType == XML_CDATA_SECTION_NODE ||
  30. $childNode->nodeType == XML_TEXT_NODE && trim(
  31. $childNode->nodeValue
  32. ) != '')
  33. ) {
  34. $typeConfig[$childNode->nodeName] = $childNode->nodeValue;
  35. }
  36. }
  37. $output[$type->attributes->getNamedItem('name')->nodeValue] = $typeConfig;
  38. }
  39. return ['types' => $output];
  40. }
  41. }