Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #28221 [DomCrawler] Add a way to filter direct children (Eine…
…nlum) This PR was squashed before being merged into the 4.2-dev branch (closes #28221). Discussion ---------- [DomCrawler] Add a way to filter direct children | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #28171 | License | MIT | Doc PR | - The Dom-Crawler component only has a `filter()` method (to filter the node and all its children) and a `children()` method to return direct children. **There is currently no way to easily filter (thanks to a selector) the direct children of a node, like jQuery allows so (with a selector passed to the `.children([selector])` method).** **This PR adds a way to optionally filter direct children thanks to a CSS selector**. Here is an example of the usage: ```php $html = <<<'HTML' <html> <body> <div id="foo"> <p class="lorem" id="p1"></p> <p class="lorem" id="p2"></p> <div id="nested"> <p class="lorem" id="p3"></p> </div> </div> </body> </html> HTML; $crawler = new Crawler($html); $foo = $crawler->filter('#foo'); $foo->children() // will select `#p1`, `#p2` and `#nested` $foo->children('p') // will select `#p1` and `p2` $foo->children('.lorem') // will select `#p1` and `p2` ``` This PR adds only an optional parameter and adds no BC break. Commits ------- f634afd [DomCrawler] Add a way to filter direct children
- Loading branch information