NodeMergingConfig.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Config\Dom;
  7. /**
  8. * Configuration of identifier attributes to be taken into account during merging
  9. */
  10. class NodeMergingConfig
  11. {
  12. /**
  13. * @var NodePathMatcher
  14. */
  15. private $nodePathMatcher;
  16. /**
  17. * Format: array('/node/path' => '<node_id_attribute>', ...)
  18. *
  19. * @var array
  20. */
  21. private $idAttributes = [];
  22. /**
  23. * @param NodePathMatcher $nodePathMatcher
  24. * @param array $idAttributes
  25. */
  26. public function __construct(NodePathMatcher $nodePathMatcher, array $idAttributes)
  27. {
  28. $this->nodePathMatcher = $nodePathMatcher;
  29. $this->idAttributes = $idAttributes;
  30. }
  31. /**
  32. * Retrieve name of an identifier attribute for a node
  33. *
  34. * @param string $nodeXpath
  35. * @return string|null
  36. */
  37. public function getIdAttribute($nodeXpath)
  38. {
  39. foreach ($this->idAttributes as $pathPattern => $idAttribute) {
  40. if ($this->nodePathMatcher->match($pathPattern, $nodeXpath)) {
  41. return $idAttribute;
  42. }
  43. }
  44. return null;
  45. }
  46. }