Skip to content

[Finder] Add documentation and code on array as method parameter #10038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 66 additions & 3 deletions components/finder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,31 @@ Restrict files by name with the

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

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

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

Multiple files names can be defined by chaining calls or using an array as parameter::

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

// same as above
$finder->files()->name(array('*.php', '*.twig'));

The ``notName()`` method excludes files matching a pattern::

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

Multiple files names can be excluded by chaining calls or using an array as parameter::

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

// same as above
$finder->files()->notName(array('*.rb', '*.py'));

.. versionadded:: 4.2
Passing an array as parameter for method ``name()`` and ``notName()`` was introduced in Symfony 4.2

File Contents
~~~~~~~~~~~~~

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

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

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

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

Multiple paths can be defined by chaining calls or using an array as parameter::

$finder->path('data')->path('foo/bar');

// same as above
$finder->path(array('data', 'foo/bar'));

.. versionadded:: 4.2
Passing an array as parameter for method ``path()`` and ``notPath()`` was introduced in Symfony 4.2

Internally, strings are converted into regular expressions by escaping slashes
and adding delimiters:

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

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

Multiple paths can be excluded by chaining calls or using an array as parameter::

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

// same as above
$finder->notPath(array('first/dir', 'other/dir'));

.. versionadded:: 4.2
Passing an array as method parameter was introduced in Symfony 4.2

File Size
~~~~~~~~~

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

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

Restrict by a size range by chaining calls::
Restrict by a size range by chaining calls or using an array as argument::

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

// same as above
$finder->files()->size(array('>= 1K', '<= 2K'));

.. versionadded:: 4.2
Passing an array as method parameter was introduced in Symfony 4.2

The comparison operator can be any of the following: ``>``, ``>=``, ``<``, ``<=``,
``==``, ``!=``.

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

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

Restrict by a date range by chaining calls or using an array as argument::

$finder->date('>= 2018-01-01')->size('<= 2018-12-31');

// same as above
$finder->date(array('>= 2018-01-01', '<= 2018-12-31'));

.. versionadded:: 4.2
Passing an array as method parameter was introduced in Symfony 4.2

The comparison operator can be any of the following: ``>``, ``>=``, ``<``, ``<=``,
``==``. You can also use ``since`` or ``after`` as an alias for ``>``, and
``until`` or ``before`` as an alias for ``<``.
Expand All @@ -293,6 +346,16 @@ traversing with :method:`Symfony\\Component\\Finder\\Finder::depth`::
$finder->depth('== 0');
$finder->depth('< 3');

Restrict by a depth range by chaining calls or using an array as argument::

$finder->depth('> 2')->depth('< 5');

// same as above
$finder->depth(array('> 2', '< 5'));

.. versionadded:: 4.2
Passing an array as method parameter was introduced in Symfony 4.2

Custom Filtering
~~~~~~~~~~~~~~~~

Expand Down