Finder
in package
implements
IteratorAggregate
uses
SmartObject
Finder allows searching through directory trees using iterator.
Finder::findFiles('*.php') ->size('> 10kB') ->from('.') ->exclude('temp');
Tags
Table of Contents
Interfaces
- IteratorAggregate
Properties
- $appends : array<string|int, string|self>
- $childFirst : bool
- $descentFilters : array<string|int, Closure>
- $filters : array<string|int, Closure>
- $find : array<string|int, array{string, string}>
- $ignoreUnreadableDirs : bool
- $in : array<string|int, string>
- $maxDepth : int
- $sort : callable|null
Methods
- __call() : mixed
- __callStatic() : mixed
- __get() : mixed
- __isset() : bool
- __set() : void
- __unset() : void
- append() : static
- Adds the specified paths or appends a new finder that returns.
- childFirst() : static
- Lists directory's contents before the directory itself. By default, this is disabled.
- collect() : array<int, FileInfo>
- Returns an array with all found files and directories.
- date() : static
- Restricts the search by modified time. $operator accepts "[operator] [date]" example: >1978-01-23
- descentFilter() : static
- It descends only to directories that match the specified filter.
- directories() : static
- Finds directories matching the specified masks.
- exclude() : static
- Skips entries that matches the given masks relative to the ones defined with the in() or from() methods.
- files() : static
- Finds files matching the specified masks.
- filter() : static
- Yields only entries which satisfy the given filter.
- find() : static
- Begins search for files and directories matching mask.
- findDirectories() : static
- Begins search for directories matching mask.
- findFiles() : static
- Begins search for files matching mask.
- from() : static
- Searches recursively from the given directories. Wildcards are allowed.
- getIterator() : Generator<string, FileInfo>
- ignoreUnreadableDirs() : static
- Ignores unreadable directories. By default, this is enabled.
- in() : static
- Searches in the given directories. Wildcards are allowed.
- limitDepth() : static
- Sets the maximum depth of entries.
- size() : static
- Restricts the search by size. $operator accepts "[operator] [size] [unit]" example: >=10kB
- sortBy() : static
- Set a compare function for sorting directory entries. The function will be called to sort entries from the same directory.
- sortByName() : static
- Sorts files in each directory naturally by name.
- addLocation() : void
- addMask() : static
- buildPattern() : string
- Converts wildcards to regular expression.
- buildPlan() : array<string, array<string|int, object{pattern: string, mode: string, recursive: bool}>>
- convertToFiles() : Generator
- proveFilters() : bool
- splitRecursivePart() : array<string|int, mixed>
- Since glob() does not know ** wildcard, we divide the path into a part for glob and a part for manual traversal.
- traverseDir() : Generator<string, FileInfo>
Properties
$appends
private
array<string|int, string|self>
$appends
= []
$childFirst
private
bool
$childFirst
= false
$descentFilters
private
array<string|int, Closure>
$descentFilters
= []
$filters
private
array<string|int, Closure>
$filters
= []
$find
private
array<string|int, array{string, string}>
$find
= []
$ignoreUnreadableDirs
private
bool
$ignoreUnreadableDirs
= true
$in
private
array<string|int, string>
$in
= []
$maxDepth
private
int
$maxDepth
= -1
$sort
private
callable|null
$sort
Methods
__call()
public
__call(string $name, array<string|int, mixed> $args) : mixed
Parameters
- $name : string
- $args : array<string|int, mixed>
Tags
__callStatic()
public
static __callStatic(string $name, array<string|int, mixed> $args) : mixed
Parameters
- $name : string
- $args : array<string|int, mixed>
Tags
__get()
public
& __get(string $name) : mixed
Parameters
- $name : string
Tags
__isset()
public
__isset(string $name) : bool
Parameters
- $name : string
Return values
bool__set()
public
__set(string $name, mixed $value) : void
Parameters
- $name : string
- $value : mixed
Tags
__unset()
public
__unset(string $name) : void
Parameters
- $name : string
Tags
append()
Adds the specified paths or appends a new finder that returns.
public
append([string|array<string|int, mixed>|null $paths = null ]) : static
Parameters
- $paths : string|array<string|int, mixed>|null = null
Return values
staticchildFirst()
Lists directory's contents before the directory itself. By default, this is disabled.
public
childFirst([bool $state = true ]) : static
Parameters
- $state : bool = true
Return values
staticcollect()
Returns an array with all found files and directories.
public
collect() : array<int, FileInfo>
Return values
array<int, FileInfo>date()
Restricts the search by modified time. $operator accepts "[operator] [date]" example: >1978-01-23
public
date(string $operator[, string|int|DateTimeInterface|null $date = null ]) : static
Parameters
- $operator : string
- $date : string|int|DateTimeInterface|null = null
Return values
staticdescentFilter()
It descends only to directories that match the specified filter.
public
descentFilter(callable(FileInfo): bool $callback) : static
Parameters
- $callback : callable(FileInfo): bool
Return values
staticdirectories()
Finds directories matching the specified masks.
public
directories([string|array<string|int, mixed> $masks = ['*'] ]) : static
Parameters
- $masks : string|array<string|int, mixed> = ['*']
Return values
staticexclude()
Skips entries that matches the given masks relative to the ones defined with the in() or from() methods.
public
exclude(string|array<string|int, mixed> $masks) : static
Parameters
- $masks : string|array<string|int, mixed>
Return values
staticfiles()
Finds files matching the specified masks.
public
files([string|array<string|int, mixed> $masks = ['*'] ]) : static
Parameters
- $masks : string|array<string|int, mixed> = ['*']
Return values
staticfilter()
Yields only entries which satisfy the given filter.
public
filter(callable(FileInfo): bool $callback) : static
Parameters
- $callback : callable(FileInfo): bool
Return values
staticfind()
Begins search for files and directories matching mask.
public
static find([string|array<string|int, mixed> $masks = ['*'] ]) : static
Parameters
- $masks : string|array<string|int, mixed> = ['*']
Return values
staticfindDirectories()
Begins search for directories matching mask.
public
static findDirectories([string|array<string|int, mixed> $masks = ['*'] ]) : static
Parameters
- $masks : string|array<string|int, mixed> = ['*']
Return values
staticfindFiles()
Begins search for files matching mask.
public
static findFiles([string|array<string|int, mixed> $masks = ['*'] ]) : static
Parameters
- $masks : string|array<string|int, mixed> = ['*']
Return values
staticfrom()
Searches recursively from the given directories. Wildcards are allowed.
public
from(string|array<string|int, mixed> $paths) : static
Parameters
- $paths : string|array<string|int, mixed>
Return values
staticgetIterator()
public
getIterator() : Generator<string, FileInfo>
Return values
Generator<string, FileInfo>ignoreUnreadableDirs()
Ignores unreadable directories. By default, this is enabled.
public
ignoreUnreadableDirs([bool $state = true ]) : static
Parameters
- $state : bool = true
Return values
staticin()
Searches in the given directories. Wildcards are allowed.
public
in(string|array<string|int, mixed> $paths) : static
Parameters
- $paths : string|array<string|int, mixed>
Return values
staticlimitDepth()
Sets the maximum depth of entries.
public
limitDepth(int|null $depth) : static
Parameters
- $depth : int|null
Return values
staticsize()
Restricts the search by size. $operator accepts "[operator] [size] [unit]" example: >=10kB
public
size(string $operator[, int|null $size = null ]) : static
Parameters
- $operator : string
- $size : int|null = null
Return values
staticsortBy()
Set a compare function for sorting directory entries. The function will be called to sort entries from the same directory.
public
sortBy(callable(FileInfo, FileInfo): int $callback) : static
Parameters
- $callback : callable(FileInfo, FileInfo): int
Return values
staticsortByName()
Sorts files in each directory naturally by name.
public
sortByName() : static
Return values
staticaddLocation()
private
addLocation(array<string|int, mixed> $paths, string $ext) : void
Parameters
- $paths : array<string|int, mixed>
- $ext : string
addMask()
private
addMask(array<string|int, mixed> $masks, string $mode) : static
Parameters
- $masks : array<string|int, mixed>
- $mode : string
Return values
staticbuildPattern()
Converts wildcards to regular expression.
private
buildPattern(string $mask) : string
Parameters
- $mask : string
Return values
stringbuildPlan()
private
buildPlan() : array<string, array<string|int, object{pattern: string, mode: string, recursive: bool}>>
Return values
array<string, array<string|int, object{pattern: string, mode: string, recursive: bool}>>convertToFiles()
private
convertToFiles(iterable<string|int, mixed> $pathNames, string $relativePath, bool $absolute) : Generator
Parameters
- $pathNames : iterable<string|int, mixed>
- $relativePath : string
- $absolute : bool
Return values
GeneratorproveFilters()
private
proveFilters(array<string|int, mixed> $filters, FileInfo $file, array<string|int, mixed> &$cache) : bool
Parameters
- $filters : array<string|int, mixed>
- $file : FileInfo
- $cache : array<string|int, mixed>
Return values
boolsplitRecursivePart()
Since glob() does not know ** wildcard, we divide the path into a part for glob and a part for manual traversal.
private
static splitRecursivePart(string $path) : array<string|int, mixed>
Parameters
- $path : string
Return values
array<string|int, mixed>traverseDir()
private
traverseDir(string $dir, array<string|int, object{pattern: string, mode: string, recursive: bool}> $searches[, array<string|int, string> $subdirs = [] ]) : Generator<string, FileInfo>
Parameters
- $dir : string
- $searches : array<string|int, object{pattern: string, mode: string, recursive: bool}>
- $subdirs : array<string|int, string> = []