From 361dde5f2635718507ebb4234ced76309eaf28f7 Mon Sep 17 00:00:00 2001 From: Julien Fredon Date: Tue, 10 Jul 2018 01:14:33 +0200 Subject: [PATCH] [Finder] Add documentation and code on array as method parameter --- components/finder.rst | 69 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/components/finder.rst b/components/finder.rst index 22b2ae41522..ae0de6998a3 100644 --- a/components/finder.rst +++ b/components/finder.rst @@ -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 ~~~~~~~~~~~~~ @@ -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: @@ -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 ~~~~~~~~~ @@ -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: ``>``, ``>=``, ``<``, ``<=``, ``==``, ``!=``. @@ -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 ``<``. @@ -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 ~~~~~~~~~~~~~~~~