Converter.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * Converter of resources configuration from \DOMDocument to array
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\App\ResourceConnection\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. * @throws \InvalidArgumentException
  17. */
  18. public function convert($source)
  19. {
  20. $output = [];
  21. /** @var \DOMNodeList $resources */
  22. $resources = $source->getElementsByTagName('resource');
  23. /** @var \DOMNode $resourceConfig */
  24. foreach ($resources as $resourceConfig) {
  25. $resourceName = $resourceConfig->attributes->getNamedItem('name')->nodeValue;
  26. $resourceData = [];
  27. foreach ($resourceConfig->attributes as $attribute) {
  28. $resourceData[$attribute->nodeName] = $attribute->nodeValue;
  29. }
  30. $output[$resourceName] = $resourceData;
  31. }
  32. return $output;
  33. }
  34. }