Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e1728a5

Browse filesBrowse files
committed
cachedNamespaces now shared by all sub crawlers
1 parent 5cb608b commit e1728a5
Copy full SHA for e1728a5

File tree

1 file changed

+7
-6
lines changed
Filter options

1 file changed

+7
-6
lines changed

‎src/Symfony/Component/DomCrawler/Crawler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Crawler.php
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class Crawler implements \Countable, \IteratorAggregate
3434
private $namespaces = [];
3535

3636
/**
37-
* @var array A map of cached namespaces
37+
* @var \ArrayIterator A map of cached namespaces
3838
*/
39-
private $cachedNamespaces = [];
39+
private $cachedNamespaces;
4040

4141
/**
4242
* @var string The base href value
@@ -73,6 +73,7 @@ public function __construct($node = null, string $uri = null, string $baseHref =
7373
$this->uri = $uri;
7474
$this->baseHref = $baseHref ?: $uri;
7575
$this->html5Parser = class_exists(HTML5::class) ? new HTML5(['disable_html_ns' => true]) : null;
76+
$this->cachedNamespaces = new \ArrayIterator();
7677

7778
$this->add($node);
7879
}
@@ -104,7 +105,7 @@ public function clear()
104105
{
105106
$this->nodes = [];
106107
$this->document = null;
107-
$this->cachedNamespaces = [];
108+
$this->cachedNamespaces = new \ArrayIterator();
108109
}
109110

110111
/**
@@ -1258,15 +1259,15 @@ private function discoverNamespace(\DOMXPath $domxpath, string $prefix): ?string
12581259
return $this->namespaces[$prefix];
12591260
}
12601261

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);
12631264
}
12641265

12651266
// ask for one namespace, otherwise we'd get a collection with an item for each node
12661267
$namespaces = $domxpath->query(sprintf('(//namespace::*[name()="%s"])[last()]', $this->defaultNamespacePrefix === $prefix ? '' : $prefix));
12671268

12681269
$namespace = ($node = $namespaces->item(0)) ? $node->nodeValue : null;
1269-
$this->cachedNamespaces[$prefix] = $namespace;
1270+
$this->cachedNamespaces->offsetSet($prefix, $namespace);
12701271

12711272
return $namespace;
12721273
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.