ArgumentParser.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\ObjectManager\Config\Mapper;
  7. use Magento\Framework\Config\Converter\Dom\Flat as FlatConverter;
  8. use Magento\Framework\Config\Dom\ArrayNodeConfig;
  9. use Magento\Framework\Config\Dom\NodePathMatcher;
  10. /**
  11. * Parser of a DI argument node that returns its array representation with no data loss
  12. */
  13. class ArgumentParser
  14. {
  15. /**
  16. * @var FlatConverter
  17. */
  18. private $converter;
  19. /**
  20. * Build and return array representation of DI argument node
  21. *
  22. * @param \DOMNode $argumentNode
  23. * @return array|string
  24. */
  25. public function parse(\DOMNode $argumentNode)
  26. {
  27. // Base path is specified to use more meaningful XPaths in config
  28. return $this->getConverter()->convert($argumentNode, 'argument');
  29. }
  30. /**
  31. * Retrieve instance of XML converter, suitable for DI argument nodes
  32. *
  33. * @return FlatConverter
  34. */
  35. protected function getConverter()
  36. {
  37. if (!$this->converter) {
  38. $arrayNodeConfig = new ArrayNodeConfig(new NodePathMatcher(), ['argument(/item)+' => 'name']);
  39. $this->converter = new FlatConverter($arrayNodeConfig);
  40. }
  41. return $this->converter;
  42. }
  43. }