Finder
in package
implements
Aggregate
Class \Hoa\File\Finder.
This class allows to find files easily by using filters and flags.
Tags
Table of Contents
Interfaces
- Aggregate
- Interface \Hoa\Iterator\Aggregate.
Properties
- $_filters : array<string|int, mixed>
- Filters.
- $_first : int
- What comes first: parent or child?
- $_flags : int
- Flags.
- $_maxDepth : int
- Max depth in recursion.
- $_paths : array<string|int, mixed>
- Paths where to look for.
- $_sorts : array<string|int, mixed>
- Sorts.
- $_splFileInfo : string
- SplFileInfo classname.
- $_types : array<string|int, mixed>
- Types of files to handle.
Methods
- __construct() : mixed
- Initialize.
- changed() : Finder
- Include files that have been changed from a certain date.
- childFirst() : Finder
- Child comes first when iterating.
- directories() : Finder
- Include directories in the result.
- dots() : Finder
- Whether we should include dots or not (respectively . and ..).
- files() : Finder
- Include files in the result.
- filter() : Finder
- Add your own filter.
- followSymlinks() : Finder
- Follow symbolink links.
- getFirst() : int
- Get first.
- getFlags() : int
- Get flags.
- getIterator() : Traversable
- Get the iterator.
- getMaxDepth() : int
- Get max depth.
- getSplFileInfo() : string
- Get SplFileInfo classname.
- getTypes() : array<string|int, mixed>
- Get types.
- in() : Finder
- Select a directory to scan.
- links() : Finder
- Include links in the result.
- maxDepth() : Finder
- Set max depth for recursion.
- modified() : Finder
- Include files that have been modified from a certain date.
- name() : Finder
- Include files that match a regex.
- notIn() : Finder
- Exclude directories that match a regex.
- owner() : Finder
- Include files that are owned by a certain owner.
- setSplFileInfo() : string
- Set SplFileInfo classname.
- size() : Finder
- Include files that respect a certain size.
- sort() : Finder
- Add your own sort.
- sortByName() : Finder
- Sort result by name.
- sortBySize() : Finder
- Sort result by size.
- formatDate() : int
- Format date.
- getFilters() : array<string|int, mixed>
- Get filters.
- getPaths() : array<string|int, mixed>
- Get all paths.
- getSorts() : array<string|int, mixed>
- Get sorts.
Properties
$_filters
Filters.
protected
array<string|int, mixed>
$_filters
= []
$_first
What comes first: parent or child?
protected
int
$_first
= -1
$_flags
Flags.
protected
int
$_flags
= -1
$_maxDepth
Max depth in recursion.
protected
int
$_maxDepth
= -1
$_paths
Paths where to look for.
protected
array<string|int, mixed>
$_paths
= []
$_sorts
Sorts.
protected
array<string|int, mixed>
$_sorts
= []
$_splFileInfo
SplFileInfo classname.
protected
string
$_splFileInfo
= 'Hoa\File\SplFileInfo'
$_types
Types of files to handle.
protected
array<string|int, mixed>
$_types
= []
Methods
__construct()
Initialize.
public
__construct() : mixed
changed()
Include files that have been changed from a certain date.
public
changed(string $date) : Finder
Example: $this->changed('since 13 days');
Parameters
- $date : string
-
Date.
Return values
FinderchildFirst()
Child comes first when iterating.
public
childFirst() : Finder
Return values
Finderdirectories()
Include directories in the result.
public
directories() : Finder
Return values
Finderdots()
Whether we should include dots or not (respectively . and ..).
public
dots([bool $flag = true ]) : Finder
Parameters
- $flag : bool = true
-
Include or not.
Return values
Finderfiles()
Include files in the result.
public
files() : Finder
Return values
Finderfilter()
Add your own filter.
public
filter(callable $callback) : Finder
The callback will receive 3 arguments: $current, $key and $iterator. It must return a boolean: true to include the file, false to exclude it. Example: // Include files that are readable $this->filter(function ($current) { return $current->isReadable(); });
Parameters
- $callback : callable
-
Callback
Return values
FinderfollowSymlinks()
Follow symbolink links.
public
followSymlinks([bool $flag = true ]) : Finder
Parameters
- $flag : bool = true
-
Whether we follow or not.
Return values
FindergetFirst()
Get first.
public
getFirst() : int
Return values
intgetFlags()
Get flags.
public
getFlags() : int
Return values
intgetIterator()
Get the iterator.
public
getIterator() : Traversable
Return values
TraversablegetMaxDepth()
Get max depth.
public
getMaxDepth() : int
Return values
intgetSplFileInfo()
Get SplFileInfo classname.
public
getSplFileInfo() : string
Return values
stringgetTypes()
Get types.
public
getTypes() : array<string|int, mixed>
Return values
array<string|int, mixed>in()
Select a directory to scan.
public
in(string|array<string|int, mixed> $paths) : Finder
Parameters
- $paths : string|array<string|int, mixed>
-
One or more paths.
Return values
Finderlinks()
Include links in the result.
public
links() : Finder
Return values
FindermaxDepth()
Set max depth for recursion.
public
maxDepth(int $depth) : Finder
Parameters
- $depth : int
-
Depth.
Return values
Findermodified()
Include files that have been modified from a certain date.
public
modified(string $date) : Finder
Example: $this->modified('since 13 days');
Parameters
- $date : string
-
Date.
Return values
Findername()
Include files that match a regex.
public
name(string $regex) : Finder
Example: $this->name('#.php$#');
Parameters
- $regex : string
-
Regex.
Return values
FindernotIn()
Exclude directories that match a regex.
public
notIn(string $regex) : Finder
Example: $this->notIn('#^.(git|hg)$#');
Parameters
- $regex : string
-
Regex.
Return values
Finderowner()
Include files that are owned by a certain owner.
public
owner(int $owner) : Finder
Parameters
- $owner : int
-
Owner.
Return values
FindersetSplFileInfo()
Set SplFileInfo classname.
public
setSplFileInfo(string $splFileInfo) : string
Parameters
- $splFileInfo : string
-
SplFileInfo classname.
Return values
stringsize()
Include files that respect a certain size.
public
size(string $size) : Finder
The size is a string of the form: operator number unit where • operator could be: <, <=, >, >= or =; • number is a positive integer; • unit could be: b (default), Kb, Mb, Gb, Tb, Pb, Eb, Zb, Yb. Example: $this->size('>= 12Kb');
Parameters
- $size : string
-
Size.
Return values
Findersort()
Add your own sort.
public
sort(callable $callable) : Finder
The callback will receive 2 arguments: $a and $b. Please see the uasort() function. Example: // Sort files by their modified time. $this->sort(function ($a, $b) { return $a->getMTime() < $b->getMTime(); });
Parameters
- $callable : callable
-
Callback.
Return values
FindersortByName()
Sort result by name.
public
sortByName([string $locale = 'root' ]) : Finder
If \Collator exists (from ext/intl), the $locale argument will be used for its constructor. Else, strcmp() will be used. Example: $this->sortByName('fr_FR');
Parameters
- $locale : string = 'root'
-
Locale.
Return values
FindersortBySize()
Sort result by size.
public
sortBySize() : Finder
Example: $this->sortBySize();
Return values
FinderformatDate()
Format date.
protected
formatDate(string $date, int &$operator) : int
Date can have the following syntax: date since date until date If the date does not have the “ago” keyword, it will be added. Example: “42 hours” is equivalent to “since 42 hours” which is equivalent to “since 42 hours ago”.
Parameters
- $date : string
-
Date.
- $operator : int
-
Operator (-1 for since, 1 for until).
Return values
intgetFilters()
Get filters.
protected
getFilters() : array<string|int, mixed>
Return values
array<string|int, mixed>getPaths()
Get all paths.
protected
getPaths() : array<string|int, mixed>
Return values
array<string|int, mixed>getSorts()
Get sorts.
protected
getSorts() : array<string|int, mixed>