class 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.
  • 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 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

public
__construct()

No description

public
mixed
getOption(string $name)

Returns an option value set on this instance.

public
setOption(string $name, mixed $value)

Set an option on this finder instance. See SS_FileFinder for the list of options available.

public
setOptions(array $options)

Sets several options at once.

public
array
find(string $base)

Finds all files matching the options within a directory. The search is performed depth first.

protected
bool
acceptDir(string $basename, string $pathname, int $depth)

Returns TRUE if the directory should be traversed. This can be overloaded to customise functionality, or extended with callbacks.

protected
bool
acceptFile(string $basename, string $pathname, int $depth)

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.

Parameters

string $name

Return Value

mixed

setOption(string $name, mixed $value)

Set an option on this finder instance. See SS_FileFinder for the list of options available.

Parameters

string $name
mixed $value

setOptions(array $options)

Sets several options at once.

Parameters

array $options

array find(string $base)

Finds all files matching the options within a directory. The search is performed depth first.

Parameters

string $base

Return Value

array

protected bool acceptDir(string $basename, string $pathname, int $depth)

Returns TRUE if the directory should be traversed. This can be overloaded to customise functionality, or extended with callbacks.

Parameters

string $basename
string $pathname
int $depth

Return Value

bool

protected bool acceptFile(string $basename, string $pathname, int $depth)

Returns TRUE if the file should be included in the results. This can be overloaded to customise functionality, or extended via callbacks.

Parameters

string $basename
string $pathname
int $depth

Return Value

bool