- ⌂ loader
- Static Methods
loader::add_namespace_path()
Add a new path to search when looking for classes within a specific namespace. The namespace is typically a package namespace. If called multiple times, the path provided in the last call will be used. It will not check previously assigned paths like other paths.
Prototype
void add_namespace_path(string $namespace, string $path)
Parameters
- namespace - The namespace to load class files from a different path for. It should be just the package namespace, without any leading or trailing slashes (ie. 'com_example_test').
- path - A string with a single path or an array of strings for multiple paths. Paths can be absolute or relative to the folder where the initial PHP script was loaded. Absolute paths start with a slash ('/'). Relative paths will be rooted in the folder of the origin PHP script (the one executed by the web server or from the CLI).
Example
require_once('path/to/comand.php');
\io_comand\loader::add_namespace_path('com_example', '/path/to/packages/com_example');
// Look for a class named library in a package named com_example and
// call the static method test(). The path/to/packages will be
// searched first, followed by all preexisting package paths.
\com_example\library::test();