18
18
*/
19
19
abstract class AbstractUriElement
20
20
{
21
+ /**
22
+ * @deprecated since Symfony 7.1, use `$domeNode` instead
23
+ */
21
24
protected \DOMElement $ node ;
25
+ protected \DOMElement |\DOM \Element $ domNode ;
22
26
protected ?string $ method ;
23
27
24
28
/**
25
- * @param \DOMElement $node A \DOMElement instance
26
- * @param string|null $currentUri The URI of the page where the link is embedded (or the base href)
27
- * @param string|null $method The method to use for the link (GET by default)
29
+ * @param \DOMElement|\DOM\Element $node A \DOMElement or a \DOM\Element instance
30
+ * @param string|null $currentUri The URI of the page where the link is embedded (or the base href)
31
+ * @param string|null $method The method to use for the link (GET by default)
28
32
*
29
33
* @throws \InvalidArgumentException if the node is not a link
30
34
*/
31
35
public function __construct (
32
- \DOMElement $ node ,
36
+ \DOMElement | \ DOM \ Element $ node ,
33
37
protected ?string $ currentUri = null ,
34
38
?string $ method = 'GET ' ,
35
39
) {
36
- $ this ->setNode ($ node );
40
+ $ this ->setDomNode ($ node );
37
41
$ this ->method = $ method ? strtoupper ($ method ) : null ;
38
42
39
43
$ elementUriIsRelative = null === parse_url (trim ($ this ->getRawUri ()), \PHP_URL_SCHEME );
@@ -44,11 +48,25 @@ public function __construct(
44
48
}
45
49
46
50
/**
47
- * Gets the node associated with this link.
51
+ * @deprecated since Symfony 7.1, use `getDomNode()` instead
48
52
*/
49
53
public function getNode (): \DOMElement
50
54
{
51
- return $ this ->node ;
55
+ trigger_deprecation ('symfony/dom-crawler ' , '7.1 ' , 'The "%s()" method is deprecated, use "%s::getDomNode()" instead. ' , __METHOD__ , __CLASS__ );
56
+
57
+ if ($ this ->domNode instanceof \DOM \Element) {
58
+ throw new \LogicException ('The node is not an instance of legacy \DOMElement. Use "getDomNode()" instead. ' );
59
+ }
60
+
61
+ return $ this ->domNode ;
62
+ }
63
+
64
+ /**
65
+ * Gets the node associated with this link.
66
+ */
67
+ public function getDomNode (): \DOMElement |\DOM \Element
68
+ {
69
+ return $ this ->domNode ;
52
70
}
53
71
54
72
/**
@@ -108,4 +126,20 @@ protected function canonicalizePath(string $path): string
108
126
* @throws \LogicException If given node is not an anchor
109
127
*/
110
128
abstract protected function setNode (\DOMElement $ node ): void ;
129
+
130
+ /**
131
+ * Sets current \DOMElement or \DOM\Element instance.
132
+ *
133
+ * @param \DOMElement|\DOM\Element $node A \DOMElement or \DOM\Element instance
134
+ *
135
+ * @throws \LogicException If given node is not an anchor
136
+ */
137
+ protected function setDomNode (\DOMElement |\DOM \Element $ node ): void
138
+ {
139
+ $ this ->domNode = $ node ;
140
+
141
+ if ($ node instanceof \DOMElement) {
142
+ $ this ->setNode ($ node );
143
+ }
144
+ }
111
145
}
0 commit comments