Skip to content

Commit 4bf5789

Browse files
committed
minor #10038 [Finder] Add documentation and code on array as method parameter (jfredon)
This PR was merged into the master branch. Discussion ---------- [Finder] Add documentation and code on array as method parameter Documents symfony/symfony#27891 Commits ------- 361dde5 [Finder] Add documentation and code on array as method parameter
2 parents fe573a3 + 361dde5 commit 4bf5789

File tree

1 file changed

+66
-3
lines changed

1 file changed

+66
-3
lines changed

components/finder.rst

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,31 @@ Restrict files by name with the
197197

198198
$finder->files()->name('*.php');
199199

200-
The ``name()`` method accepts globs, strings, or regexes::
200+
The ``name()`` method accepts globs, strings, regexes or an array of globs, strings or regexes::
201201

202202
$finder->files()->name('/\.php$/');
203203

204+
Multiple files names can be defined by chaining calls or using an array as parameter::
205+
206+
$finder->files()->name('*.php')->name('*.twig');
207+
208+
// same as above
209+
$finder->files()->name(array('*.php', '*.twig'));
210+
204211
The ``notName()`` method excludes files matching a pattern::
205212

206213
$finder->files()->notName('*.rb');
207214

215+
Multiple files names can be excluded by chaining calls or using an array as parameter::
216+
217+
$finder->files()->notName('*.rb')->notName('*.py');
218+
219+
// same as above
220+
$finder->files()->notName(array('*.rb', '*.py'));
221+
222+
.. versionadded:: 4.2
223+
Passing an array as parameter for method ``name()`` and ``notName()`` was introduced in Symfony 4.2
224+
208225
File Contents
209226
~~~~~~~~~~~~~
210227

@@ -234,11 +251,21 @@ Restrict files and directories by path with the
234251

235252
On all platforms slash (i.e. ``/``) should be used as the directory separator.
236253

237-
The ``path()`` method accepts a string or a regular expression::
254+
The ``path()`` method accepts a string, a regular expression or an array of strings or regulars expressions::
238255

239256
$finder->path('foo/bar');
240257
$finder->path('/^foo\/bar/');
241258

259+
Multiple paths can be defined by chaining calls or using an array as parameter::
260+
261+
$finder->path('data')->path('foo/bar');
262+
263+
// same as above
264+
$finder->path(array('data', 'foo/bar'));
265+
266+
.. versionadded:: 4.2
267+
Passing an array as parameter for method ``path()`` and ``notPath()`` was introduced in Symfony 4.2
268+
242269
Internally, strings are converted into regular expressions by escaping slashes
243270
and adding delimiters:
244271

@@ -251,6 +278,16 @@ The :method:`Symfony\\Component\\Finder\\Finder::notPath` method excludes files
251278

252279
$finder->notPath('other/dir');
253280

281+
Multiple paths can be excluded by chaining calls or using an array as parameter::
282+
283+
$finder->notPath('first/dir')->notPath('other/dir');
284+
285+
// same as above
286+
$finder->notPath(array('first/dir', 'other/dir'));
287+
288+
.. versionadded:: 4.2
289+
Passing an array as method parameter was introduced in Symfony 4.2
290+
254291
File Size
255292
~~~~~~~~~
256293

@@ -259,10 +296,16 @@ Restrict files by size with the
259296

260297
$finder->files()->size('< 1.5K');
261298

262-
Restrict by a size range by chaining calls::
299+
Restrict by a size range by chaining calls or using an array as argument::
263300

264301
$finder->files()->size('>= 1K')->size('<= 2K');
265302

303+
// same as above
304+
$finder->files()->size(array('>= 1K', '<= 2K'));
305+
306+
.. versionadded:: 4.2
307+
Passing an array as method parameter was introduced in Symfony 4.2
308+
266309
The comparison operator can be any of the following: ``>``, ``>=``, ``<``, ``<=``,
267310
``==``, ``!=``.
268311

@@ -278,6 +321,16 @@ Restrict files by last modified dates with the
278321

279322
$finder->date('since yesterday');
280323

324+
Restrict by a date range by chaining calls or using an array as argument::
325+
326+
$finder->date('>= 2018-01-01')->size('<= 2018-12-31');
327+
328+
// same as above
329+
$finder->date(array('>= 2018-01-01', '<= 2018-12-31'));
330+
331+
.. versionadded:: 4.2
332+
Passing an array as method parameter was introduced in Symfony 4.2
333+
281334
The comparison operator can be any of the following: ``>``, ``>=``, ``<``, ``<=``,
282335
``==``. You can also use ``since`` or ``after`` as an alias for ``>``, and
283336
``until`` or ``before`` as an alias for ``<``.
@@ -293,6 +346,16 @@ traversing with :method:`Symfony\\Component\\Finder\\Finder::depth`::
293346
$finder->depth('== 0');
294347
$finder->depth('< 3');
295348

349+
Restrict by a depth range by chaining calls or using an array as argument::
350+
351+
$finder->depth('> 2')->depth('< 5');
352+
353+
// same as above
354+
$finder->depth(array('> 2', '< 5'));
355+
356+
.. versionadded:: 4.2
357+
Passing an array as method parameter was introduced in Symfony 4.2
358+
296359
Custom Filtering
297360
~~~~~~~~~~~~~~~~
298361

0 commit comments

Comments
 (0)