update lock clucknut
All checks were successful
All checks were successful
This commit is contained in:
55
vendor/symfony/finder/Finder.php
vendored
55
vendor/symfony/finder/Finder.php
vendored
@@ -57,8 +57,10 @@ class Finder implements \IteratorAggregate, \Countable
|
||||
private bool $reverseSorting = false;
|
||||
private \Closure|int|false $sort = false;
|
||||
private int $ignore = 0;
|
||||
/** @var list<string> */
|
||||
private array $dirs = [];
|
||||
private array $dates = [];
|
||||
/** @var list<iterable<SplFileInfo|\SplFileInfo|string>> */
|
||||
private array $iterators = [];
|
||||
private array $contains = [];
|
||||
private array $notContains = [];
|
||||
@@ -666,27 +668,33 @@ public function in(string|array $dirs): static
|
||||
*/
|
||||
public function getIterator(): \Iterator
|
||||
{
|
||||
if (0 === \count($this->dirs) && 0 === \count($this->iterators)) {
|
||||
if (!$this->dirs && !$this->iterators) {
|
||||
throw new \LogicException('You must call one of in() or append() methods before iterating over a Finder.');
|
||||
}
|
||||
|
||||
if (1 === \count($this->dirs) && 0 === \count($this->iterators)) {
|
||||
if (1 === \count($this->dirs) && !$this->iterators) {
|
||||
$iterator = $this->searchInDirectory($this->dirs[0]);
|
||||
|
||||
if ($this->sort || $this->reverseSorting) {
|
||||
$iterator = (new SortableIterator($iterator, $this->sort, $this->reverseSorting))->getIterator();
|
||||
} else {
|
||||
$iterator = new \AppendIterator();
|
||||
foreach ($this->dirs as $dir) {
|
||||
$iterator->append(new \IteratorIterator(new LazyIterator(fn () => $this->searchInDirectory($dir))));
|
||||
}
|
||||
|
||||
return $iterator;
|
||||
}
|
||||
foreach ($this->iterators as $it) {
|
||||
$iterator->append(new \IteratorIterator(new LazyIterator(static function () use ($it) {
|
||||
foreach ($it as $file) {
|
||||
if (!$file instanceof \SplFileInfo) {
|
||||
$file = new \SplFileInfo($file);
|
||||
}
|
||||
$key = $file->getPathname();
|
||||
if (!$file instanceof SplFileInfo) {
|
||||
$file = new SplFileInfo($key, $file->getPath(), $key);
|
||||
}
|
||||
|
||||
$iterator = new \AppendIterator();
|
||||
foreach ($this->dirs as $dir) {
|
||||
$iterator->append(new \IteratorIterator(new LazyIterator(fn () => $this->searchInDirectory($dir))));
|
||||
}
|
||||
|
||||
foreach ($this->iterators as $it) {
|
||||
$iterator->append($it);
|
||||
yield $key => $file;
|
||||
}
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->sort || $this->reverseSorting) {
|
||||
@@ -701,26 +709,13 @@ public function getIterator(): \Iterator
|
||||
*
|
||||
* The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
|
||||
*
|
||||
* @return $this
|
||||
* @param iterable<SplFileInfo|\SplFileInfo|string> $iterator
|
||||
*
|
||||
* @throws \InvalidArgumentException when the given argument is not iterable
|
||||
* @return $this
|
||||
*/
|
||||
public function append(iterable $iterator): static
|
||||
{
|
||||
if ($iterator instanceof \IteratorAggregate) {
|
||||
$this->iterators[] = $iterator->getIterator();
|
||||
} elseif ($iterator instanceof \Iterator) {
|
||||
$this->iterators[] = $iterator;
|
||||
} elseif (is_iterable($iterator)) {
|
||||
$it = new \ArrayIterator();
|
||||
foreach ($iterator as $file) {
|
||||
$file = $file instanceof \SplFileInfo ? $file : new \SplFileInfo($file);
|
||||
$it[$file->getPathname()] = $file;
|
||||
}
|
||||
$this->iterators[] = $it;
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Finder::append() method wrong argument type.');
|
||||
}
|
||||
$this->iterators[] = $iterator;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user