SS_FileFinder
class SS_FileFinder (View source)
A utility class that finds any files matching a set of rules that are present within a directory tree.
Each file finder instance can have several options set on it:
- name_regex (string): A regular expression that file basenames must match.
- accept_callback (callback): A callback that is called to accept a file. If it returns false the item will be skipped. The callback is passed the basename, pathname and depth.
- accept_dir_callback (callback): The same as accept_callback, but only called for directories.
- accept_file_callback (callback): The same as accept_callback, but only called for files.
- file_callback (callback): A callback that is called when a file i succesfully matched. It is passed the basename, pathname and depth.
- dir_callback (callback): The same as file_callback, but called for directories.
- ignore_files (array): An array of file names to skip.
- ignore_dirs (array): An array of directory names to skip.
- ignore_vcs (bool): Skip over commonly used VCS dirs (svn, git, hg, bzr). This is enabled by default. The names of VCS directories to skip over are defined in SS_FileFInder::$vcs_dirs.
- max_depth (int): The maxmium depth to traverse down the folder tree, default to unlimited.
Properties
protected static | array | $vcs_dirs | ||
protected static | array | $default_options | The default options that are set on a new finder instance. Options not present in this array cannot be set. |
|
protected | array | $options |
Methods
Set an option on this finder instance. See SS_FileFinder for the list of options available.
Finds all files matching the options within a directory. The search is performed depth first.
Returns TRUE if the directory should be traversed. This can be overloaded to customise functionality, or extended with callbacks.
Returns TRUE if the file should be included in the results. This can be overloaded to customise functionality, or extended via callbacks.
Details
__construct()
No description
mixed
getOption(string $name)
Returns an option value set on this instance.
setOption(string $name, mixed $value)
Set an option on this finder instance. See SS_FileFinder for the list of options available.
setOptions(array $options)
Sets several options at once.
array
find(string $base)
Finds all files matching the options within a directory. The search is performed depth first.
protected bool
acceptDir($basename, $pathname, $depth)
Returns TRUE if the directory should be traversed. This can be overloaded to customise functionality, or extended with callbacks.
protected bool
acceptFile($basename, $pathname, $depth)
Returns TRUE if the file should be included in the results. This can be overloaded to customise functionality, or extended via callbacks.