@@ -34,9 +34,9 @@ class Crawler implements \Countable, \IteratorAggregate
34
34
private $ namespaces = [];
35
35
36
36
/**
37
- * @var array A map of cached namespaces
37
+ * @var \ArrayIterator A map of cached namespaces
38
38
*/
39
- private $ cachedNamespaces = [] ;
39
+ private $ cachedNamespaces ;
40
40
41
41
/**
42
42
* @var string The base href value
@@ -73,6 +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
77
77
78
$ this ->add ($ node );
78
79
}
@@ -104,7 +105,7 @@ public function clear()
104
105
{
105
106
$ this ->nodes = [];
106
107
$ this ->document = null ;
107
- $ this ->cachedNamespaces = [] ;
108
+ $ this ->cachedNamespaces = new \ ArrayIterator () ;
108
109
}
109
110
110
111
/**
@@ -1258,15 +1259,15 @@ private function discoverNamespace(\DOMXPath $domxpath, string $prefix): ?string
1258
1259
return $ this ->namespaces [$ prefix ];
1259
1260
}
1260
1261
1261
- if (\array_key_exists ( $ prefix , $ this ->cachedNamespaces )) {
1262
- return $ this ->cachedNamespaces [ $ prefix] ;
1262
+ if ($ this ->cachedNamespaces -> offsetExists ( $ prefix )) {
1263
+ return $ this ->cachedNamespaces -> offsetGet ( $ prefix) ;
1263
1264
}
1264
1265
1265
1266
// ask for one namespace, otherwise we'd get a collection with an item for each node
1266
1267
$ namespaces = $ domxpath ->query (sprintf ('(//namespace::*[name()="%s"])[last()] ' , $ this ->defaultNamespacePrefix === $ prefix ? '' : $ prefix ));
1267
1268
1268
1269
$ namespace = ($ node = $ namespaces ->item (0 )) ? $ node ->nodeValue : null ;
1269
- $ this ->cachedNamespaces [ $ prefix] = $ namespace ;
1270
+ $ this ->cachedNamespaces -> offsetSet ( $ prefix, $ namespace) ;
1270
1271
1271
1272
return $ namespace ;
1272
1273
}
0 commit comments