phpBB API Documentation
Class

phpbb\class_loader

class class_loader

The class loader resolves class names to file system paths and loads them if necessary.

Classes have to be of the form phpbb(dir)(classpart_), so directory names must never contain underscores. Example: phpbbdirsubdirclassname is a valid class name, while phpbbdirsubdirclass_name is not.

If every part of the class name is a directory, the last directory name is also used as the filename, e.g. phpbb_dir would resolve to dir/dir.php.

Methods

__construct(string $namespace, string $path, string $php_ext = 'php', driver_interface $cache = null)

Creates a new \phpbb\class_loader, which loads files with the given file extension from the given path.

set_cache(driver_interface $cache = null)

Provide the class loader with a cache to store paths.

register()

Registers the class loader as an autoloader using SPL.

unregister()

Removes the class loader from the SPL autoloader stack.

string|bool resolve_path(string $class)

Resolves a phpBB class name to a relative path which can be included.

load_class(string $class)

Resolves a class name to a path and then includes it.

Details

at line 51
public __construct(string $namespace, string $path, string $php_ext = 'php', driver_interface $cache = null)

Creates a new \phpbb\class_loader, which loads files with the given file extension from the given path.

Parameters

string $namespace Required namespace for files to be loaded
string $path Directory to load files from
string $php_ext The file extension for PHP files
driver_interface $cache An implementation of the phpBB cache interface.

at line 72
public set_cache(driver_interface $cache = null)

Provide the class loader with a cache to store paths.

If set to null, the the class loader will resolve paths by checking for the existance of every directory in the class name every time.

Parameters

driver_interface $cache An implementation of the phpBB cache interface.

at line 90
public register()

Registers the class loader as an autoloader using SPL.

at line 98
public unregister()

Removes the class loader from the SPL autoloader stack.

at line 112
public string|bool resolve_path(string $class)

Resolves a phpBB class name to a relative path which can be included.

Parameters

string $class The class name to resolve, must be in the namespace the loader was constructed with. Has to begin with \

Return Value

string|bool A relative path to the file containing the class or false if looking it up failed.

at line 145
public load_class(string $class)

Resolves a class name to a path and then includes it.

Parameters

string $class The class name which is being loaded.