Watcher
extends Finder
in package
implements
Listenable
uses
Listens
Class \Hoa\File\Watcher.
A naive file system watcher that fires three events: new, move and modify.
Tags
Table of Contents
Interfaces
- Listenable
- Interface \Hoa\Event\Listenable.
Properties
- $_filters : array<string|int, mixed>
- Filters.
- $_first : int
- What comes first: parent or child?
- $_flags : int
- Flags.
- $_latency : int
- Latency.
- $_listener : Listener
- Listener instance.
- $_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
- Constructor.
- 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.
- getLatency() : int
- Get latency.
- 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.
- on() : Listenable
- Attach a callable to a listenable component.
- owner() : Finder
- Include files that are owned by a certain owner.
- run() : void
- Run the watcher.
- setLatency() : int
- Set latency.
- 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.
- getListener() : Listener
- Get listener.
- getPaths() : array<string|int, mixed>
- Get all paths.
- getSorts() : array<string|int, mixed>
- Get sorts.
- setListener() : Listener
- Set listener.
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
$_latency
Latency.
protected
int
$_latency
= 1
$_listener
Listener instance.
protected
Listener
$_listener
= null
$_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()
Constructor.
public
__construct([int $latency = null ]) : mixed
Parameters
- $latency : int = null
-
Latency (in seconds).
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
TraversablegetLatency()
Get latency.
public
getLatency() : int
Return values
intgetMaxDepth()
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
Finderon()
Attach a callable to a listenable component.
public
on(string $listenerId, mixed $callable) : Listenable
Parameters
- $listenerId : string
-
Listener ID.
- $callable : mixed
-
Callable.
Return values
Listenableowner()
Include files that are owned by a certain owner.
public
owner(int $owner) : Finder
Parameters
- $owner : int
-
Owner.
Return values
Finderrun()
Run the watcher.
public
run() : void
Listenable events: • new, when a file is new, i.e. found by the finder; • modify, when a file has been modified; • move, when a file has moved, i.e. no longer found by the finder.
setLatency()
Set latency.
public
setLatency(int $latency) : int
Parameters
- $latency : int
-
Latency (in seconds).
Return values
intsetSplFileInfo()
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>getListener()
Get listener.
protected
getListener() : Listener
Return values
ListenergetPaths()
Get all paths.
protected
getPaths() : array<string|int, mixed>
Return values
array<string|int, mixed>getSorts()
Get sorts.
protected
getSorts() : array<string|int, mixed>
Return values
array<string|int, mixed>setListener()
Set listener.
protected
setListener(Listener $listener) : Listener
Parameters
- $listener : Listener
-
Listener.