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] Added a way to inverse a previous sorting#27967

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
fabpot merged 1 commit intosymfony:masterfromlyrixx:finder-reverse-iterator
Oct 10, 2018

Conversation

@lyrixx
Copy link
Member

@lyrixxlyrixx commentedJul 16, 2018
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT
Doc PR

Sometimes, it's useful to inverse the previous sorting.
For exemple when you want to display the most recent uploaded files

lbrunet and lyrixx reacted with heart emoji
@lyrixxlyrixxforce-pushed thefinder-reverse-iterator branch 2 times, most recently fromf4bbc64 tob80853bCompareJuly 16, 2018 14:16
*
* @return $this
*/
publicfunctionreverseSorting(bool$reverseSorting =true)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Just asking: why allow passing an argument here instead of doing this:

publicfunctionreverseSorting(){$this->reverseSorting =true;return$this;}

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Because there is no way to reset a finder, so if you want to use it many time, but with different options, it's better to have a "real" setter

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

but that's inconsistent with most other APIs, which cannot be reset either.

If you really want to have a bunch of common config for the Finder, and then some changes, the solution is to apply all the common config, and then clone the object before applying each variant

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fair enough ; I fixed the code

@lyrixxlyrixxforce-pushed thefinder-reverse-iterator branch fromb80853b to36b151fCompareJuly 16, 2018 15:00
{
publicfunction__construct(iterable$iterator)
{
parent::__construct(array_reverse(iterator_to_array($iterator)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

iterable can be array, so you don't neediterator_to_array in that case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Well, the typehint should beTraversable then, to keep the code simple. The Finder component does not need support for arrays.

ro0NL reacted with thumbs up emoji
{
publicfunction__construct(iterable$iterator)
{
parent::__construct(array_reverse(iterator_to_array($iterator)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The SortableIterator is usingiterator_to_array($this->iterator, true). So should we do the same here ?

@lyrixxlyrixxforce-pushed thefinder-reverse-iterator branch from36b151f to329bd50CompareJuly 17, 2018 11:51
@lyrixx
Copy link
MemberAuthor

@stof I addressed your comments. Thanks

}

/**
* Reverse the sorting.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

reverses

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks, Fixed

{
publicfunction__construct(\Traversable$iterator)
{
parent::__construct(array_reverse(iterator_to_array($iterator,true)));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Instead of doing the reversing in the constructor, it should be done in aIteratorIterator::getIterator() method, like theSortableIterator does.
Which makes me wonder: should this concern be added toSortableIterator instead? Looks very related to me.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You are right about the constructor vsgetIterator. I have fixed the code.

About moving it to SortableIterator, I don't think it's a good idea

  1. If you don't sort, you can not reverse the sort. This is a bit weird, but if people want to reverse the "natural sorting" with this implemention, they could.
  2. Composition is a better design

Sometimes, it's useful to inverse the previous sorting.For exemple when you want to display the most recent uploaded files
@lyrixxlyrixxforce-pushed thefinder-reverse-iterator branch from27bc298 to3cd0dcaCompareJuly 23, 2018 08:50
@nicolas-grekas
Copy link
Member

nicolas-grekas commentedJul 23, 2018
edited
Loading

If you don't sort, you can not reverse the sort

we can, e.g. with aSortableIterator::SORT_NONE = 0 const

Composition is a better design

not always: here, composition forces a double call to iterator_to_array + an extra call to array_reverse, whileSortableIterator could handle that in one run by multiplying the return values of the comparator functions with 1/-1 depending on the sorting direction.

@nicolas-grekas
Copy link
Member

ping@lyrixx

@fabpot
Copy link
Member

Thank you@lyrixx.

OskarStark reacted with heart emoji

@fabpotfabpot merged commit3cd0dca intosymfony:masterOct 10, 2018
fabpot added a commit that referenced this pull requestOct 10, 2018
…rixx)This PR was merged into the 4.2-dev branch.Discussion----------[Finder] Added a way to inverse a previous sorting| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets || License       | MIT| Doc PR        |---Sometimes, it's useful to inverse the previous sorting.For exemple when you want to display the most recent uploaded filesCommits-------3cd0dca [Finder] Added a way to inverse a previous sorting
fabpot added a commit that referenced this pull requestOct 10, 2018
…s-grekas)This PR was merged into the 4.2-dev branch.Discussion----------[Finder] make reverse sorting a bit more generic| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#27967 (comment)| License       | MIT| Doc PR        | -Commits-------ce861d1 [Finder] make reverse sorting a bit more generic
@lyrixxlyrixx deleted the finder-reverse-iterator branchOctober 11, 2018 08:36
@nicolas-grekasnicolas-grekas modified the milestones:next,4.2Nov 1, 2018
This was referencedNov 3, 2018
joshtrichards pushed a commit to joshtrichards/symfony-finder that referenced this pull requestApr 26, 2024
…s-grekas)This PR was merged into the 4.2-dev branch.Discussion----------[Finder] make reverse sorting a bit more generic| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |symfony/symfony#27967 (comment)| License       | MIT| Doc PR        | -Commits-------340ede3 [Finder] make reverse sorting a bit more generic
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@javiereguiluzjaviereguiluzjaviereguiluz left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@stofstofstof left review comments

@fabpotfabpotfabpot approved these changes

@OskarStarkOskarStarkOskarStark approved these changes

+1 more reviewer

@ro0NLro0NLro0NL left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

8 participants

@lyrixx@nicolas-grekas@fabpot@javiereguiluz@stof@OskarStark@ro0NL@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp