SilverStripe\Assets\FileFinder
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.
- dir_regexp (string): A regular expression that dir 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 .
- max_depth (int): The maxmium depth to traverse down the folder tree,
default to unlimited.
Synopsis
- // members
- protected static array $vcs_dirs = ;
- protected static array $default_options = ;
- protected array $options = ;
- // methods
- public void __construct()
- public mixed getOption()
- public void setOption()
- public void setOptions()
- public array find()
- protected bool acceptDir()
- protected bool acceptFile()
Members
protected
- $default_options
—
array
The default options that are set on a new finder instance. Options not present in this array cannot be set. - $options — array
- $vcs_dirs — array
Methods
protected
- acceptDir() — Returns TRUE if the directory should be traversed. This can be overloaded to customise functionality, or extended with callbacks.
- acceptFile() — Returns TRUE if the file should be included in the results. This can be overloaded to customise functionality, or extended via callbacks.
public
- __construct()
- find() — Finds all files matching the options within a directory. The search is performed depth first.
- getOption() — Returns an option value set on this instance.
- setOption() — Set an option on this finder instance. See {@link SS_FileFinder} for the list of options available.
- setOptions() — Sets several options at once.