From 79162c1eb5ba7be211005c5debe4d017f5d9a63e Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Wed, 7 Nov 2018 17:41:49 +0300 Subject: [PATCH] [DomCrawler] Added return of element name in `extract()` method --- src/Symfony/Component/DomCrawler/CHANGELOG.md | 5 +++++ src/Symfony/Component/DomCrawler/Crawler.php | 2 ++ src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php | 2 ++ 3 files changed, 9 insertions(+) diff --git a/src/Symfony/Component/DomCrawler/CHANGELOG.md b/src/Symfony/Component/DomCrawler/CHANGELOG.md index dc773be06d65b..3accde4bf5738 100644 --- a/src/Symfony/Component/DomCrawler/CHANGELOG.md +++ b/src/Symfony/Component/DomCrawler/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +4.3.0 +----- + +* Added return of element name (`_name`) in `extract()` method. + 4.2.0 ----- diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index 455e030955eaa..a70c6466e0686 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -658,6 +658,8 @@ public function extract($attributes) foreach ($attributes as $attribute) { if ('_text' === $attribute) { $elements[] = $node->nodeValue; + } elseif ('_name' === $attribute) { + $elements[] = $node->nodeName; } else { $elements[] = $node->getAttribute($attribute); } diff --git a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php index 9e73eaae1d9c2..254b1ba7f3206 100644 --- a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php @@ -416,6 +416,8 @@ public function testExtract() $this->assertEquals(array(array(), array(), array()), $crawler->extract(array()), '->extract() returns empty arrays if the attribute list is empty'); $this->assertEquals(array(), $this->createTestCrawler()->filterXPath('//ol')->extract('_text'), '->extract() returns an empty array if the node list is empty'); + + $this->assertEquals(array(array('One', 'li'), array('Two', 'li'), array('Three', 'li')), $crawler->extract(array('_text', '_name')), '->extract() returns an array of extracted data from the node list'); } public function testFilterXpathComplexQueries() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy