diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index d4e452f6f0dd..fae8cc624944 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -40,6 +40,11 @@ class Crawler extends \SplObjectStorage */ private $baseHref; + /** + * @var \DOMDocument|null + */ + private $document; + /** * Whether the Crawler contains HTML or XML content (used when converting CSS to XPath). * @@ -68,6 +73,7 @@ public function __construct($node = null, $currentUri = null, $baseHref = null) public function clear() { parent::removeAll($this); + $this->document = null; } /** @@ -307,6 +313,14 @@ public function addNodes(array $nodes) */ public function addNode(\DOMNode $node) { + if (null !== $this->document && $this->document !== $node->ownerDocument) { + @trigger_error('Attaching DOM nodes from multiple documents in a Crawler is deprecated as of 2.8 and will be forbidden in 3.0.', E_USER_DEPRECATED); + } + + if (null === $this->document) { + $this->document = $node->ownerDocument; + } + if ($node instanceof \DOMDocument) { parent::attach($node->documentElement); } else { @@ -1152,6 +1166,7 @@ private function createSubCrawler($nodes) { $crawler = new static($nodes, $this->uri, $this->baseHref); $crawler->isHtml = $this->isHtml; + $crawler->document = $this->document; return $crawler; } diff --git a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php index cdd87dd7a8d1..f3a5b40b5a60 100755 --- a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php @@ -20,7 +20,10 @@ public function testConstructor() $crawler = new Crawler(); $this->assertCount(0, $crawler, '__construct() returns an empty crawler'); - $crawler = new Crawler(new \DOMNode()); + $doc = new \DOMDocument(); + $node = $doc->createElement('test'); + + $crawler = new Crawler($node); $this->assertCount(1, $crawler, '__construct() takes a node as a first argument'); } @@ -71,6 +74,14 @@ public function testAddHtmlContent() $crawler->addHtmlContent('
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: