@@ -34,7 +34,7 @@ class Crawler implements \Countable, \IteratorAggregate
34
34
private $ namespaces = [];
35
35
36
36
/**
37
- * @var \ArrayIterator A map of cached namespaces
37
+ * @var \ArrayObject A map of cached namespaces
38
38
*/
39
39
private $ cachedNamespaces ;
40
40
@@ -73,7 +73,7 @@ public function __construct($node = null, string $uri = null, string $baseHref =
73
73
$ this ->uri = $ uri ;
74
74
$ this ->baseHref = $ baseHref ?: $ uri ;
75
75
$ this ->html5Parser = class_exists (HTML5 ::class) ? new HTML5 (['disable_html_ns ' => true ]) : null ;
76
- $ this ->cachedNamespaces = new \ArrayIterator ();
76
+ $ this ->cachedNamespaces = new \ArrayObject ();
77
77
78
78
$ this ->add ($ node );
79
79
}
@@ -105,7 +105,7 @@ public function clear()
105
105
{
106
106
$ this ->nodes = [];
107
107
$ this ->document = null ;
108
- $ this ->cachedNamespaces = new \ArrayIterator ();
108
+ $ this ->cachedNamespaces = new \ArrayObject ();
109
109
}
110
110
111
111
/**
@@ -1198,17 +1198,14 @@ private function discoverNamespace(\DOMXPath $domxpath, string $prefix): ?string
1198
1198
return $ this ->namespaces [$ prefix ];
1199
1199
}
1200
1200
1201
- if ($ this ->cachedNamespaces -> offsetExists ( $ prefix )) {
1202
- return $ this ->cachedNamespaces -> offsetGet ( $ prefix) ;
1201
+ if (isset ( $ this ->cachedNamespaces [ $ prefix] )) {
1202
+ return $ this ->cachedNamespaces [ $ prefix] ;
1203
1203
}
1204
1204
1205
1205
// ask for one namespace, otherwise we'd get a collection with an item for each node
1206
1206
$ namespaces = $ domxpath ->query (sprintf ('(//namespace::*[name()="%s"])[last()] ' , $ this ->defaultNamespacePrefix === $ prefix ? '' : $ prefix ));
1207
1207
1208
- $ namespace = ($ node = $ namespaces ->item (0 )) ? $ node ->nodeValue : null ;
1209
- $ this ->cachedNamespaces ->offsetSet ($ prefix , $ namespace );
1210
-
1211
- return $ namespace ;
1208
+ return $ this ->cachedNamespaces [$ prefix ] = ($ node = $ namespaces ->item (0 )) ? $ node ->nodeValue : null ;
1212
1209
}
1213
1210
1214
1211
private function findNamespacePrefixes (string $ xpath ): array
0 commit comments