update lock clucknut
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 14s
Build, Push and Deploy / build-and-push (push) Successful in 3m14s
Build, Push and Deploy / deploy-staging (push) Successful in 25s
Build, Push and Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-04-18 20:32:18 +07:00
parent 4554035227
commit dcaf267458
3359 changed files with 153185 additions and 205489 deletions

View File

@@ -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;
}