19 declare(strict_types=1);
49 private array
$vcsPatterns = [
'.svn',
'_svn',
'CVS',
'_darcs',
'.arch-params',
'.monotone',
'.bzr',
'.git',
'.hg'];
70 $this->ignore = self::IGNORE_VCS_FILES|self::IGNORE_DOT_FILES;
101 public function exclude(array $directories): self
103 array_walk($directories,
static function ($directory):
void {
104 if (!is_string($directory)) {
109 $clone = clone $this;
110 $clone->exclude = array_merge($clone->exclude, $directories);
119 public function in(array $directories): self
121 array_walk($directories,
static function ($directory):
void {
122 if (!is_string($directory)) {
127 $clone = clone $this;
128 $clone->dirs = array_unique(array_merge($clone->dirs, $directories));
144 public function depth(
string|
int $level): self
146 $clone = clone $this;
167 public function date(
string $date): self
169 $clone = clone $this;
188 public function size(
string|
int|array $sizes): self
192 $clone = clone $this;
194 foreach ($sizes as $size) {
203 $clone = clone $this;
204 $clone->reverseSorting =
true;
211 $clone = clone $this;
213 $clone->ignore |= self::IGNORE_VCS_FILES;
227 array_walk($pattern,
static function ($p):
void {
228 if (!is_string($p)) {
233 $clone = clone $this;
234 foreach ($pattern as $p) {
235 $clone->vcsPatterns[] = $p;
238 $clone->vcsPatterns = array_unique($clone->vcsPatterns);
250 $clone = clone $this;
251 $clone->sort = $closure;
256 public function sortByName(
bool $useNaturalSort =
false): self
258 $clone = clone $this;
260 if ($useNaturalSort) {
269 $clone = clone $this;
277 $clone = clone $this;
288 public function append(iterable $iterator): self
290 $clone = clone $this;
293 $clone->iterators[] = $iterator->getIterator();
295 $clone->iterators[] = $iterator;
296 } elseif (is_iterable($iterator)) {
298 foreach ($iterator as $file) {
303 'Finder::append() method wrong argument type in passed iterator.' 307 $clone->iterators[] = $it;
317 if (self::IGNORE_VCS_FILES === (self::IGNORE_VCS_FILES&$this->ignore)) {
333 if ($this->mode !== 0) {
352 $iterator = $iteratorAggregate->getIterator();
363 #[\ReturnTypeWillChange] 366 if ([] === $this->dirs && [] === $this->iterators) {
367 throw new LogicException(
'You must call one of in() or append() methods before iterating over a Finder.');
370 if (1 ===
count($this->dirs) && [] === $this->iterators) {
375 foreach ($this->dirs as $dir) {
379 foreach ($this->iterators as $it) {
380 $iterator->append($it);
size(string|int|array $sizes)
Adds tests for file sizes.
__construct(private Filesystem $filesystem)
ignoreVCS(bool $ignoreVCS)
sort(Closure $closure)
Sorts files and directories by an anonymous function.
const SORT_BY_NAME_NATURAL
addVCSPattern(array $pattern)
searchInDirectory(string $dir)
depth(string|int $level)
Adds tests for the directory depth.
exclude(array $directories)
date(string $date)
Adds tests for file dates.
append(iterable $iterator)
Appends an existing set of files/directories to the finder.
sortByName(bool $useNaturalSort=false)