File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -43,9 +43,23 @@ The ``$file`` variable is an instance of
43
43
44
44
.. warning ::
45
45
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
+ }
49
63
50
64
Searching for Files and Directories
51
65
-----------------------------------
You can’t perform that action at this time.
0 commit comments