-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathNodeMergingConfig.php
63 lines (58 loc) · 1.49 KB
/
NodeMergingConfig.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\FunctionalTestingFramework\Config\Dom;
/**
* Configuration of identifier attributes to be taken into account during merging
*/
class NodeMergingConfig
{
/**
* Matching of XPath expressions to path patterns.
*
* @var NodePathMatcher
*/
private $nodePathMatcher;
/**
* Format: array('/node/path' => '<node_id_attribute>', ...)
*
* @var array
*/
private $idAttributes = [];
/**
* NodeMergingConfig constructor.
* @param NodePathMatcher $nodePathMatcher
* @param array $idAttributes
*/
public function __construct(NodePathMatcher $nodePathMatcher, array $idAttributes)
{
$this->nodePathMatcher = $nodePathMatcher;
$this->idAttributes = $idAttributes;
}
/**
* Retrieve name of an identifier attribute for a node
*
* @param string $nodeXpath
* @return string|null
*/
public function getIdAttribute($nodeXpath)
{
foreach ($this->idAttributes as $pathPattern => $idAttribute) {
if ($this->nodePathMatcher->match($pathPattern, $nodeXpath)) {
return $idAttribute;
}
}
return null;
}
/**
* Getter to return nodePathMatcher for convenience
*
* @return NodePathMatcher
*/
public function getNodePathMatcher()
{
return $this->nodePathMatcher;
}
}