class finder

The finder provides a simple way to locate files in the core and a set of extensions

Properties

protected $extensions
protected $filesystem
protected $phpbb_root_path
protected $cache
protected $php_ext
protected string $cache_name

The cache variable name used to store $this->cached_queries in $this->cache.

protected array $query

An associative array, containing all search parameters set in methods.

protected array $cached_queries

A map from md5 hashes of serialized queries to their previously retrieved results.

Methods

__construct(filesystem_interface $filesystem, string $phpbb_root_path = '', service $cache = null, string $php_ext = 'php', string $cache_name = '_ext_finder')

Creates a new finder instance with its dependencies

set_extensions(array $extensions, bool $replace_list = true)

Set the array of extensions

core_path(string $core_path)

Sets a core path to be searched in addition to extensions

suffix(string $suffix)

Sets the suffix all files found in extensions and core must match.

extension_suffix(string $extension_suffix)

Sets a suffix all files found in extensions must match

core_suffix(string $core_suffix)

Sets a suffix all files found in the core path must match

prefix(string $prefix)

Sets the prefix all files found in extensions and core must match

extension_prefix(string $extension_prefix)

Sets a prefix all files found in extensions must match

core_prefix(string $core_prefix)

Sets a prefix all files found in the core path must match

directory(string $directory)

Sets a directory all files found in extensions and core must be contained in

extension_directory(string $extension_directory)

Sets a directory all files found in extensions must be contained in

core_directory(string $core_directory)

Sets a directory all files found in the core path must be contained in

string
sanitise_directory(string $directory)

Removes occurrences of /./ and makes sure path ends without trailing slash

array
get_classes(bool $cache = true)

Finds classes matching the configured options if they follow phpBB naming rules.

array
get_classes_from_files(array $files)

Get class names from a list of files

array
get_directories(bool $cache = true, bool $extension_keys = false)

Finds all directories matching the configured options

array
get_files(bool $cache = true)

Finds all files matching the configured options.

array
find_with_root_path(bool $cache = true, bool $is_dir = false, bool $extension_keys = false)

A wrapper around the general find which prepends a root path to results

array
find(bool $cache = true, bool $is_dir = false)

Finds all file system entries matching the configured options

array
find_from_extension(string $extension_name, string $extension_path, bool $cache = true, bool $is_dir = false)

Finds all file system entries matching the configured options for one specific extension

array
find_from_paths(array $extensions, bool $cache = true, bool $is_dir = false)

Finds all file system entries matching the configured options from an array of paths

Details

at line 58
__construct(filesystem_interface $filesystem, string $phpbb_root_path = '', service $cache = null, string $php_ext = 'php', string $cache_name = '_ext_finder')

Creates a new finder instance with its dependencies

Parameters

filesystem_interface $filesystem

Filesystem instance

string $phpbb_root_path

Path to the phpbb root directory

service $cache

A cache instance or null

string $php_ext

php file extension

string $cache_name

The name of the cache variable, defaults to _ext_finder

at line 87
finder set_extensions(array $extensions, bool $replace_list = true)

Set the array of extensions

Parameters

array $extensions

A list of extensions that should be searched as well

bool $replace_list

Should the list be emptied before adding the extensions

Return Value

finder

This object for chaining calls

at line 107
finder core_path(string $core_path)

Sets a core path to be searched in addition to extensions

Parameters

string $core_path

The path relative to phpbb_root_path

Return Value

finder

This object for chaining calls

at line 123
finder suffix(string $suffix)

Sets the suffix all files found in extensions and core must match.

There is no default file extension, so to find PHP files only, you will have to specify .php as a suffix. However when using get_classes, the .php file extension is automatically added to suffixes.

Parameters

string $suffix

A filename suffix

Return Value

finder

This object for chaining calls

at line 140
finder extension_suffix(string $extension_suffix)

Sets a suffix all files found in extensions must match

There is no default file extension, so to find PHP files only, you will have to specify .php as a suffix. However when using get_classes, the .php file extension is automatically added to suffixes.

Parameters

string $extension_suffix

A filename suffix

Return Value

finder

This object for chaining calls

at line 156
finder core_suffix(string $core_suffix)

Sets a suffix all files found in the core path must match

There is no default file extension, so to find PHP files only, you will have to specify .php as a suffix. However when using get_classes, the .php file extension is automatically added to suffixes.

Parameters

string $core_suffix

A filename suffix

Return Value

finder

This object for chaining calls

at line 168
finder prefix(string $prefix)

Sets the prefix all files found in extensions and core must match

Parameters

string $prefix

A filename prefix

Return Value

finder

This object for chaining calls

at line 181
finder extension_prefix(string $extension_prefix)

Sets a prefix all files found in extensions must match

Parameters

string $extension_prefix

A filename prefix

Return Value

finder

This object for chaining calls

at line 193
finder core_prefix(string $core_prefix)

Sets a prefix all files found in the core path must match

Parameters

string $core_prefix

A filename prefix

Return Value

finder

This object for chaining calls

at line 208
finder directory(string $directory)

Sets a directory all files found in extensions and core must be contained in

Automatically sets the core_directory if its value does not differ from the current directory.

Parameters

string $directory

Return Value

finder

This object for chaining calls

at line 221
finder extension_directory(string $extension_directory)

Sets a directory all files found in extensions must be contained in

Parameters

string $extension_directory

Return Value

finder

This object for chaining calls

at line 233
finder core_directory(string $core_directory)

Sets a directory all files found in the core path must be contained in

Parameters

string $core_directory

Return Value

finder

This object for chaining calls

at line 245
protected string sanitise_directory(string $directory)

Removes occurrences of /./ and makes sure path ends without trailing slash

Parameters

string $directory

A directory pattern

Return Value

string

A cleaned up directory pattern

at line 269
array get_classes(bool $cache = true)

Finds classes matching the configured options if they follow phpBB naming rules.

The php file extension is automatically added to suffixes.

Note: If a file is matched but contains a class name not following the phpBB naming rules an incorrect class name will be returned.

Parameters

bool $cache

Whether the result should be cached

Return Value

array

An array of found class names

at line 285
array get_classes_from_files(array $files)

Get class names from a list of files

Parameters

array $files

Array of files (from find())

Return Value

array

Array of class names

at line 312
array get_directories(bool $cache = true, bool $extension_keys = false)

Finds all directories matching the configured options

Parameters

bool $cache

Whether the result should be cached

bool $extension_keys

Whether the result should have extension name as array key

Return Value

array

An array of paths to found directories

at line 323
array get_files(bool $cache = true)

Finds all files matching the configured options.

Parameters

bool $cache

Whether the result should be cached

Return Value

array

An array of paths to found files

at line 338
protected array find_with_root_path(bool $cache = true, bool $is_dir = false, bool $extension_keys = false)

A wrapper around the general find which prepends a root path to results

Parameters

bool $cache

Whether the result should be cached

bool $is_dir

Directories will be returned when true, only files otherwise

bool $extension_keys

If true, result will be associative array with extension name as key

Return Value

array

An array of paths to found items

at line 366
array find(bool $cache = true, bool $is_dir = false)

Finds all file system entries matching the configured options

Parameters

bool $cache

Whether the result should be cached

bool $is_dir

Directories will be returned when true, only files otherwise

Return Value

array

An array of paths to found items

at line 396
array find_from_extension(string $extension_name, string $extension_path, bool $cache = true, bool $is_dir = false)

Finds all file system entries matching the configured options for one specific extension

Parameters

string $extension_name

Name of the extension

string $extension_path

Relative path to the extension root directory

bool $cache

Whether the result should be cached

bool $is_dir

Directories will be returned when true, only files otherwise

Return Value

array

An array of paths to found items

at line 423
array find_from_paths(array $extensions, bool $cache = true, bool $is_dir = false)

Finds all file system entries matching the configured options from an array of paths

Parameters

array $extensions

Array of extensions (name => full relative path)

bool $cache

Whether the result should be cached

bool $is_dir

Directories will be returned when true, only files otherwise

Return Value

array

An array of paths to found items