Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
javiereguiluz merged 2 commits intosymfony:masterfromvyshkant:finder_natural_ordering
Jun 1, 2018
Merged
Changes fromall 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 deletionscomponents/finder.rst
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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

[8]ページ先頭

©2009-2025 Movatter.jp