class Finder implements IteratorAggregate, Countable
Finder allows to build rules to find files and directories.
It is a thin wrapper around several specialized iterator classes.
All rules may be invoked several times.
All methods return the current Finder object to allow easy chaining:
$finder = Finder::create()->files()->name('*.php')->in(__DIR__);
Constants
| IGNORE_VCS_FILES |
|
| IGNORE_DOT_FILES |
|
Methods
|
__construct()
Constructor. |
||
| static Finder |
create()
Creates a new Finder. |
|
| Finder |
addAdapter(AdapterInterface $adapter, integer $priority)
Registers a finder engine implementation. |
|
| Finder |
useBestAdapter()
Sets the selected adapter to the best one according to the current platform the code is run on. |
|
| Finder |
setAdapter(string $name)
Selects the adapter to use. |
|
| Finder |
removeAdapters()
Removes all adapters registered in the finder. |
|
| AdapterInterface[] |
getAdapters()
Returns registered adapters ordered by priority without extra information. |
|
| Finder |
directories()
Restricts the matching to directories only. |
|
| Finder |
files()
Restricts the matching to files only. |
|
| Finder |
depth(int $level)
Adds tests for the directory depth. |
|
| Finder |
date(string $date)
Adds tests for file dates (last modified). |
|
| Finder |
name(string $pattern)
Adds rules that files must match. |
|
| Finder |
notName(string $pattern)
Adds rules that files must not match. |
|
| Finder |
contains(string $pattern)
Adds tests that file contents must match. |
|
| Finder |
notContains(string $pattern)
Adds tests that file contents must not match. |
|
| Finder |
path(string $pattern)
Adds rules that filenames must match. |
|
| Finder |
notPath(string $pattern)
Adds rules that filenames must not match. |
|
| Finder |
size(string $size)
Adds tests for file sizes. |
|
| Finder |
exclude(string|array $dirs)
Excludes directories. |
|
| Finder |
ignoreDotFiles(Boolean $ignoreDotFiles)
Excludes "hidden" directories and files (starting with a dot). |
|
| Finder |
ignoreVCS(Boolean $ignoreVCS)
Forces the finder to ignore version control directories. |
|
| static |
addVCSPattern(string|string[] $pattern)
Adds VCS patterns. |
|
| Finder |
sort(Closure $closure)
Sorts files and directories by an anonymous function. |
|
| Finder |
sortByName()
Sorts files and directories by name. |
|
| Finder |
sortByType()
Sorts files and directories by type (directories before files), then by name. |
|
| Finder |
sortByAccessedTime()
Sorts files and directories by the last accessed time. |
|
| Finder |
sortByChangedTime()
Sorts files and directories by the last inode changed time. |
|
| Finder |
sortByModifiedTime()
Sorts files and directories by the last modified time. |
|
| Finder |
filter(Closure $closure)
Filters the iterator with an anonymous function. |
|
| Finder |
followLinks()
Forces the following of symlinks. |
|
| Finder |
ignoreUnreadableDirs(boolean $ignore = true)
Tells finder to ignore unreadable directories. |
|
| Finder |
in(string|array $dirs)
Searches files and directories which match defined rules. |
|
| Iterator |
getIterator()
Returns an Iterator for the current Finder configuration. |
|
| Finder |
append(mixed $iterator)
Appends an existing set of files/directories to the finder. |
|
| int |
count()
Counts all the results collected by the iterators. |
Details
at line 65
public
__construct()
Constructor.
at line 84
static public Finder
create()
Creates a new Finder.
at line 97
public Finder
addAdapter(AdapterInterface $adapter, integer $priority)
Registers a finder engine implementation.
at line 113
public Finder
useBestAdapter()
Sets the selected adapter to the best one according to the current platform the code is run on.
at line 129
public Finder
setAdapter(string $name)
Selects the adapter to use.
at line 146
public Finder
removeAdapters()
Removes all adapters registered in the finder.
at line 158
public AdapterInterface[]
getAdapters()
Returns registered adapters ordered by priority without extra information.
at line 172
public Finder
directories()
Restricts the matching to directories only.
at line 186
public Finder
files()
Restricts the matching to files only.
at line 210
public Finder
depth(int $level)
Adds tests for the directory depth.
Usage:
$finder->depth('> 1') // the Finder will start matching at level 1.
$finder->depth('< 3') // the Finder will descend at most 3 levels of directories below the starting point.
at line 237
public Finder
date(string $date)
Adds tests for file dates (last modified).
The date must be something that strtotime() is able to parse:
$finder->date('since yesterday');
$finder->date('until 2 days ago');
$finder->date('> now - 2 hours');
$finder->date('>= 2005-10-15');
at line 261
public Finder
name(string $pattern)
Adds rules that files must match.
You can use patterns (delimited with / sign), globs or simple strings.
$finder->name('*.php')
$finder->name('/\.php$/') // same as above
$finder->name('test.php')
at line 279
public Finder
notName(string $pattern)
Adds rules that files must not match.
at line 300
public Finder
contains(string $pattern)
Adds tests that file contents must match.
Strings or PCRE patterns can be used:
$finder->contains('Lorem ipsum')
$finder->contains('/Lorem ipsum/i')
at line 321
public Finder
notContains(string $pattern)
Adds tests that file contents must not match.
Strings or PCRE patterns can be used:
$finder->notContains('Lorem ipsum')
$finder->notContains('/Lorem ipsum/i')
at line 344
public Finder
path(string $pattern)
Adds rules that filenames must match.
You can use patterns (delimited with / sign) or simple strings.
$finder->path('some/special/dir')
$finder->path('/some\/special\/dir/') // same as above
Use only / as dirname separator.
at line 367
public Finder
notPath(string $pattern)
Adds rules that filenames must not match.
You can use patterns (delimited with / sign) or simple strings.
$finder->notPath('some/special/dir')
$finder->notPath('/some\/special\/dir/') // same as above
Use only / as dirname separator.
at line 390
public Finder
size(string $size)
Adds tests for file sizes.
$finder->size('> 10K');
$finder->size('<= 1Ki');
$finder->size(4);
at line 408
public Finder
exclude(string|array $dirs)
Excludes directories.
at line 426
public Finder
ignoreDotFiles(Boolean $ignoreDotFiles)
Excludes "hidden" directories and files (starting with a dot).
at line 448
public Finder
ignoreVCS(Boolean $ignoreVCS)
Forces the finder to ignore version control directories.
at line 466
static public
addVCSPattern(string|string[] $pattern)
Adds VCS patterns.
at line 490
public Finder
sort(Closure $closure)
Sorts files and directories by an anonymous function.
The anonymous function receives two \SplFileInfo instances to compare.
This can be slow as all the matching files and directories must be retrieved for comparison.
at line 508
public Finder
sortByName()
Sorts files and directories by name.
This can be slow as all the matching files and directories must be retrieved for comparison.
at line 526
public Finder
sortByType()
Sorts files and directories by type (directories before files), then by name.
This can be slow as all the matching files and directories must be retrieved for comparison.
at line 546
public Finder
sortByAccessedTime()
Sorts files and directories by the last accessed time.
This is the time that the file was last accessed, read or written to.
This can be slow as all the matching files and directories must be retrieved for comparison.
at line 568
public Finder
sortByChangedTime()
Sorts files and directories by the last inode changed time.
This is the time that the inode information was last modified (permissions, owner, group or other metadata).
On Windows, since inode is not available, changed time is actually the file creation time.
This can be slow as all the matching files and directories must be retrieved for comparison.
at line 588
public Finder
sortByModifiedTime()
Sorts files and directories by the last modified time.
This is the last time the actual contents of the file were last modified.
This can be slow as all the matching files and directories must be retrieved for comparison.
at line 609
public Finder
filter(Closure $closure)
Filters the iterator with an anonymous function.
The anonymous function receives a \SplFileInfo and must return false
to remove files.
at line 623
public Finder
followLinks()
Forces the following of symlinks.
at line 639
public Finder
ignoreUnreadableDirs(boolean $ignore = true)
Tells finder to ignore unreadable directories.
By default, scanning unreadable directories content throws an AccessDeniedException.
at line 657
public Finder
in(string|array $dirs)
Searches files and directories which match defined rules.
at line 685
public Iterator
getIterator()
Returns an Iterator for the current Finder configuration.
This method implements the IteratorAggregate interface.
at line 718
public Finder
append(mixed $iterator)
Appends an existing set of files/directories to the finder.
The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
at line 742
public int
count()
Counts all the results collected by the iterators.