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 #9 8000 671

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 1 commit
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
Next Next commit
[Finder] Described "use natural sort" option
  • Loading branch information
vyshkant committed Apr 24, 2018
commit 0d38d1bbc5ac113bc8fd29a4ad71f0fc2aed8010
22 changes: 14 additions & 8 deletions components/finder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,22 @@ 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.
To sort by name using `natural sort order`_ algorithm,
pass ``true`` as the first argument of ``sortByName()`` method.

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 +325,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