Commit f03a54e
committed
feature #28221 [DomCrawler] Add a way to filter direct children (Einenlum)
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 childrenFile tree
2 files changed
+57
-6
lines changed- src/Symfony/Component/DomCrawler
- Tests
2 files changed
+57
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
501 | 501 | | |
502 | 502 | | |
503 | 503 | | |
| 504 | + | |
| 505 | + | |
504 | 506 | | |
505 | 507 | | |
506 | 508 | | |
| 509 | + | |
507 | 510 | | |
508 | | - | |
| 511 | + | |
509 | 512 | | |
| 513 | + | |
| 514 | + | |
510 | 515 | | |
511 | 516 | | |
512 | 517 | | |
513 | 518 | | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
514 | 526 | | |
515 | 527 | | |
516 | 528 | | |
| |||
691 | 703 | | |
692 | 704 | | |
693 | 705 | | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
| 706 | + | |
699 | 707 | | |
700 | 708 | | |
701 | 709 | | |
| |||
1148 | 1156 | | |
1149 | 1157 | | |
1150 | 1158 | | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
1151 | 1171 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1004 | 1004 | | |
1005 | 1005 | | |
1006 | 1006 | | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
1007 | 1038 | | |
1008 | 1039 | | |
1009 | 1040 | | |
| |||
0 commit comments