66
77use Brick \StructuredData \Item ;
88use Brick \StructuredData \Reader ;
9- use DOMDocument ;
10- use DOMNode ;
11- use DOMXPath ;
9+ use DOM \ HTMLDocument ;
10+ use DOM \ Node ;
11+ use DOM \ XPath ;
1212use Override ;
1313use Sabre \Uri \InvalidUriException ;
1414
@@ -93,9 +93,9 @@ final class RdfaLiteReader implements Reader
9393 ];
9494
9595 #[Override]
96- public function read (DOMDocument $ document , string $ url ): array
96+ public function read (HTMLDocument $ document , string $ url ): array
9797 {
98- $ xpath = new DOMXPath ($ document );
98+ $ xpath = new XPath ($ document );
9999
100100 /**
101101 * Top-level item has a typeof attribute and no property attribute.
@@ -104,22 +104,22 @@ public function read(DOMDocument $document, string $url): array
104104 $ nodes = iterator_to_array ($ nodes );
105105
106106 return array_map (
107- fn (DOMNode $ node ) => $ this ->nodeToItem ($ node , $ xpath , $ url , self ::PREDEFINED_PREFIXES , null ),
107+ fn (Node $ node ) => $ this ->nodeToItem ($ node , $ xpath , $ url , self ::PREDEFINED_PREFIXES , null ),
108108 $ nodes ,
109109 );
110110 }
111111
112112 /**
113- * Extracts information from a DOMNode into an Item.
113+ * Extracts information from a Node into an Item.
114114 *
115- * @param DOMNode $node A DOMNode representing an element with the typeof attribute.
116- * @param DOMXPath $xpath A DOMXPath object created from the node's document element.
115+ * @param Node $node A Node representing an element with the typeof attribute.
116+ * @param XPath $xpath A XPath object created from the node's document element.
117117 * @param string $url The URL the document was retrieved from, for relative URL resolution.
118118 * @param string[] $prefixes The prefixes in use, as a map of prefix to vocabulary URL.
119119 * @param string|null $vocabulary The URL of the vocabulary in use, if any.
120120 * This is the content of the vocab attribute of the closest item ancestor.
121121 */
122- private function nodeToItem (DOMNode $ node , DOMXPath $ xpath , string $ url , array $ prefixes , ?string $ vocabulary ): Item
122+ private function nodeToItem (Node $ node , XPath $ xpath , string $ url , array $ prefixes , ?string $ vocabulary ): Item
123123 {
124124 $ vocabulary = $ this ->updateVocabulary ($ node , $ vocabulary );
125125
@@ -165,7 +165,7 @@ private function nodeToItem(DOMNode $node, DOMXPath $xpath, string $url, array $
165165
166166 // Exclude properties that are inside a nested item; XPath does not seem to provide a way to do this.
167167 // See: https://stackoverflow.com/q/26365495/759866
168- $ properties = array_filter ($ properties , function (DOMNode $ itemprop ) use ($ node , $ xpath ) {
168+ $ properties = array_filter ($ properties , function (Node $ itemprop ) use ($ node , $ xpath ) {
169169 for (; ;) {
170170 $ itemprop = $ itemprop ->parentNode ;
171171
@@ -182,7 +182,7 @@ private function nodeToItem(DOMNode $node, DOMXPath $xpath, string $url, array $
182182 return false ;
183183 });
184184
185- /** @var DOMNode [] $properties */
185+ /** @var Node [] $properties */
186186 foreach ($ properties as $ property ) {
187187 $ names = $ property ->attributes ->getNamedItem ('property ' )->textContent ;
188188
@@ -261,12 +261,12 @@ private function isValidAbsoluteURL(string $url): bool
261261 /**
262262 * Replaces the current vocabulary with the one from the vocab attribute of the current node, if set.
263263 *
264- * @param DOMNode $node The DOMNode that may contain a vocab attribute.
264+ * @param Node $node The Node that may contain a vocab attribute.
265265 * @param string|null $vocabulary The URL of the vocabulary in use, if any.
266266 *
267267 * @return string|null The updated vocabulary URL, if any.
268268 */
269- private function updateVocabulary (DOMNode $ node , ?string $ vocabulary ): ?string
269+ private function updateVocabulary (Node $ node , ?string $ vocabulary ): ?string
270270 {
271271 $ vocab = $ node ->attributes ->getNamedItem ('vocab ' );
272272
@@ -310,13 +310,13 @@ private function checkVocabularyUrl(string $url): ?string
310310 /**
311311 * @see https://www.w3.org/TR/microdata/#values
312312 *
313- * @param DOMNode $node A DOMNode representing an element with the property attribute.
314- * @param DOMXPath $xpath A DOMXPath object created from the node's document element.
313+ * @param Node $node A Node representing an element with the property attribute.
314+ * @param XPath $xpath A XPath object created from the node's document element.
315315 * @param string $url The URL the document was retrieved from, for relative URL resolution.
316316 * @param string[] $prefixes The prefixes in use, as a map of prefix to vocabulary URL.
317317 * @param string|null $vocabulary The URL of the vocabulary in use, if any.
318318 */
319- private function getPropertyValue (DOMNode $ node , DOMXPath $ xpath , string $ url , array $ prefixes , ?string $ vocabulary ): Item |string
319+ private function getPropertyValue (Node $ node , XPath $ xpath , string $ url , array $ prefixes , ?string $ vocabulary ): Item |string
320320 {
321321 // If the element also has an typeof attribute, create an item from the element
322322 $ attr = $ node ->attributes ->getNamedItem ('typeof ' );
0 commit comments