Skip to content

Commit fd82b50

Browse files
committed
Merge branch '7.4' into 8.0
* 7.4: [Finder] Show how to clone the finder to reuse its configuration
2 parents 6613a54 + c41d93f commit fd82b50

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

components/finder.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,23 @@ The ``$file`` variable is an instance of
4343

4444
.. warning::
4545

46-
The ``Finder`` object doesn't reset its internal state automatically.
47-
This means that you need to create a new instance if you do not want
48-
to get mixed results.
46+
The ``Finder`` object is stateful. Any method call will change all its
47+
instances. If you need to perform several searches, create multiple instances
48+
of ``Finder`` or clone it after setting the common configuration::
49+
50+
$finder = new Finder();
51+
// first, configure the common options for the following searches
52+
$finder->files()->in('./templates');
53+
54+
// then, clone the finder to create a new instance before searching for files
55+
foreach ((clone $finder)->name('partial_*') as $file) {
56+
echo('Processing partials config: ' . $file->getRelativePathname());
57+
}
58+
59+
// without cloning, the previous ->name() call would affect this search
60+
foreach ((clone $finder)->name('partial_*')->name('plugin_*') as $file) {
61+
echo('Processing plugin config: ' . $file->getRelativePathname());
62+
}
4963

5064
Searching for Files and Directories
5165
-----------------------------------

0 commit comments

Comments
 (0)