Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commita15a9d5

Browse files
committed
[#2638] Adding versionadded and type-hints to make Closure argument even more obvious
1 parented0920e commita15a9d5

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

‎components/dom_crawler.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ This allows you to use jQuery-like selectors to traverse::
7070

7171
Anonymous function can be used to filter with more complex criteria::
7272

73-
$crawler = $crawler->filter('body > p')->reduce(function ($node, $i) {
73+
use Symfony\Component\DomCrawler\Crawler;
74+
// ...
75+
76+
$crawler = $crawler->filter('body > p')->reduce(function (Crawler $node, $i) {
7477
// filter even nodes
7578
return ($i % 2) == 0;
7679
});
@@ -137,10 +140,18 @@ Extract attribute and/or node values from the list of nodes::
137140

138141
Call an anonymous function on each node of the list::
139142

140-
$nodeValues = $crawler->filter('p')->each(function ($node, $i) {
143+
use Symfony\Component\DomCrawler\Crawler;
144+
// ...
145+
146+
$nodeValues = $crawler->filter('p')->each(function (Crawler $node, $i) {
141147
return $node->text();
142148
});
143149

150+
..versionadded::
151+
As seen here, in Symfony 2.3, the ``each`` and ``reduce`` Closure functions
152+
are passed a ``Crawler`` as the first argument. Previously, that argument
153+
was a:phpclass:`DOMNode`.
154+
144155
The anonymous function receives the position and the node (as a Crawler) as arguments.
145156
The result is an array of values returned by the anonymous function calls.
146157

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp