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: phpbb_dir_subdir_class_name is a valid class name, while phpbb_dir_sub_dir_class_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. If set to null, the the class loader will resolve paths by checking for the existence of every directory in the class name every time.

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
__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
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 existence of every directory in the class name every time.

Parameters

driver_interface $cache

An implementation of the phpBB cache interface.

at line 90
register()

Registers the class loader as an autoloader using SPL.

at line 98
unregister()

Removes the class loader from the SPL autoloader stack.

at line 112
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
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.