8000 [Finder] Described "use natural sort" option by vyshkant · Pull Request #9671 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[Finder] Described "use natural sort" option #9671

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
merged 2 commits into from
Jun 1, 2018
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
27 changes: 19 additions & 8 deletions components/finder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,27 @@ 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::

$finder->sort(function (\SplFileInfo $a, \SplFileInfo $b) {
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
~~~~~~~~~

Expand Down Expand Up @@ -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
0