8000 [Finder] Sort works per directory when multiple directories are given · Issue #34879 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Finder] Sort works per directory when multiple directories are given #34879

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

Closed
flip111 opened this issue Dec 8, 2019 · 5 comments
Closed

[Finder] Sort works per directory when multiple directories are given #34879

flip111 opened this issue Dec 8, 2019 · 5 comments

Comments

@flip111
Copy link
Contributor
flip111 commented Dec 8, 2019

symfony 5

<?php

use Symfony\Component\Finder\Finder;

require_once getenv()['APPDATA'] . '/Composer/vendor/autoload.php';

function makeEmptyFile(string $path, int $size) {
  $fp = fopen($path, 'w');
  fseek($fp, $size-1, SEEK_CUR);
  fwrite($fp,'a');
  fclose($fp);
}

function createDir(string $path) {
  if (! file_exists($path)) {
    mkdir($path);
  }
}

$tmp = getenv()['TEMP'];

createDir($tmp . '/finder');
createDir($tmp . '/finder/1');
createDir($tmp . '/finder/2');

makeEmptyFile($tmp . '/finder/1/a', 30);
makeEmptyFile($tmp . '/finder/1/b', 10);
makeEmptyFile($tmp . '/finder/2/c', 20);
makeEmptyFile($tmp . '/finder/2/d', 40);

$finder = new Finder();

$finder->files()
  ->in($tmp . '/finder/1')
  ->in($tmp . '/finder/2')
  ->sort(function (\SplFileInfo $a, \SplFileInfo $b) {
    return ($a->getSize() <=> $b->getSize());
  });

foreach ($finder as $file) {
  dump($file->getRealPath());
}

result

^ "C:\Users\flip111\AppData\Local\Temp\finder\1\b"
^ "C:\Users\flip111\AppData\Local\Temp\finder\1\a"
^ "C:\Users\flip111\AppData\Local\Temp\finder\2\c"
^ "C:\Users\flip111\AppData\Local\Temp\finder\2\d"

expected result

^ "C:\Users\flip111\AppData\Local\Temp\finder\1\b"
^ "C:\Users\flip111\AppData\Local\Temp\finder\2\c"
^ "C:\Users\flip111\AppData\Local\Temp\finder\1\a"
^ "C:\Users\flip111\AppData\Local\Temp\finder\2\d"
@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Hello? This issue is about to be closed if nobody replies.

@flip111
Copy link
Contributor Author
flip111 commented Jan 2, 2021

.

@carsonbot carsonbot removed the Stalled label Jan 2, 2021
@xabbuh
Copy link
Member
xabbuh commented Jan 4, 2021

Status: Reviewed

@xabbuh
Copy link
Member
xabbuh commented Jan 4, 2021

see #39703

@fabpot fabpot closed this as completed Jan 5, 2021
fabpot added a commit that referenced this issue Jan 5, 2021
…t (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[Finder] apply the sort callback on the whole search result

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34879
| License       | MIT
| Doc PR        |

Commits
-------

1261051 apply the sort callback on the whole search result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0