symfony: [Finder] Duplicated results when used two times

Hello,

When i run the code below, on the second search, the results are duplicated.

$finder = new Finder();
$first_results = $finder->in('/my/path')->files()->name('/my_pattern/');

 // [...] some code

$second_results = $finder->in('/my/path')->files()->name('/another_pattern/');

But if i run that code, it works as intended :

$finder = new Finder();
$first_results = $finder->in('/my/path')->files()->name('/my_pattern/');

 // [...] some code

$finder = new Finder();
$second_results = $finder->in('/my/path')->files()->name('/another_pattern/');

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Reactions: 2
  • Comments: 21 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Sorry for the old post, but what about providing some kind of a “reset” method on the finder instance, that would reset only the memorized path(s) ? This would allow to keep the same research criteria, but for a search in another directory.

Sorry for the old post, but providing a “reset” method would be useful here.

Edit: Finder::create() returns a new instance, this will do 😃

It’s not the same. create return a really new finder. You may want to add some initial filter, get all matching files, reset it, then get others file.

@javiereguiluz The issue with create() is that it creates a completely new instance (i.e. dropping all the configuration you did before). As far as I understood comments users seem to want to reuse an instance and only do some “finetuning” before getting the next results.

What about the comment from @J7mbo above?

Finder::create() returns a new instance, this will do 😃

So we don’t need to add a reset() method, right?

A reset() method looks like something that could be added without pain.

@symfony/deciders What do you think?

@lyrixx This is exactly what I wrote 😉 Closing as there is no good solution without BC breaks.