diff --git a/components/finder.rst b/components/finder.rst index 790e0cf7bdc..22b2ae41522 100644 --- a/components/finder.rst +++ b/components/finder.rst @@ -168,10 +168,15 @@ Sort the result by name or by type (directories first, then files):: $finder->sortByType(); -.. note:: +.. tip:: - Notice that the ``sort*`` methods need to get all matching elements to do - their jobs. For large iterators, it is slow. + By default, the ``sortByName()`` method uses the :phpfunction:`strcmp` PHP + function (e.g. ``file1.txt``, ``file10.txt``, ``file2.txt``). Pass ``true`` + as its argument to use PHP's `natural sort order`_ algorithm instead (e.g. + ``file1.txt``, ``file2.txt``, ``file10.txt``). + + .. versionadded:: 4.2 + The option to use the natural sort order was introduced in Symfony 4.2. You can also define your own sorting algorithm with ``sort()`` method:: @@ -179,6 +184,11 @@ You can also define your own sorting algorithm with ``sort()`` method:: return strcmp($a->getRealPath(), $b->getRealPath()); }); +.. note:: + + Notice that the ``sort*`` methods need to get all matching elements to do + their jobs. For large iterators, it is slow. + File Name ~~~~~~~~~ @@ -320,8 +330,9 @@ The contents of returned files can be read with // ... } -.. _strtotime: https://php.net/manual/en/datetime.formats.php -.. _protocol: https://php.net/manual/en/wrappers.php -.. _Streams: https://php.net/streams -.. _IEC standard: https://physics.nist.gov/cuu/Units/binary.html -.. _Packagist: https://packagist.org/packages/symfony/finder +.. _strtotime: https://php.net/manual/en/datetime.formats.php +.. _protocol: https://php.net/manual/en/wrappers.php +.. _Streams: https://php.net/streams +.. _IEC standard: https://physics.nist.gov/cuu/Units/binary.html +.. _Packagist: https://packagist.org/packages/symfony/finder +.. _`natural sort order`: https://en.wikipedia.org/wiki/Natural_sort_order