The helper to autoload class using php namespace.
More...
The helper to autoload class using php namespace.
Based on PSR-4 Autoloader https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md
A root prefix and base directory can be added to all ns to work with non full standardized project.
- Since
- 2.25
__construct |
( |
string |
$root_prefix = '' , |
|
|
string |
$root_base_dir = '' , |
|
|
bool |
$prepend = false |
|
) |
| |
Register loader with SPL autoloader stack.
- Parameters
-
string | $root_prefix | Common ns prefix |
string | $root_base_dir | Common dir prefix |
bool | $prepend | Add loader on top of stack |
References loadClass(), normalizeBaseDir(), and normalizePrefix().
Get root prefix.
- Returns
- string Root prefix
References $root_prefix.
Get root base directory.
- Returns
- string Root base directory
References $root_base_dir.
normalizePrefix |
( |
string |
$prefix | ) |
|
normalizeBaseDir |
( |
string |
$base_dir | ) |
|
Normalize base directory.
- Parameters
-
string | $base_dir | Dir prefix |
- Returns
- string Base dir with right directory separator
Referenced by __construct(), and addNamespace().
qualifyNamespace |
( |
string |
$str | ) |
|
Clean up a string into namespace part.
- Parameters
-
string | $str | String to clean |
- Returns
- null|string Cleaned string or null if empty
References normalizePrefix().
addNamespace |
( |
string |
$prefix, |
|
|
string |
$base_dir, |
|
|
bool |
$prepend = false |
|
) |
| |
Adds a base directory for a namespace prefix.
- Parameters
-
string | $prefix | The namespace prefix |
string | $base_dir | A base directory for class files in the namespace |
bool | $prepend | If true, prepend the base directory to the stack instead of appending it; this causes it to be searched first rather than last |
References normalizeBaseDir(), and normalizePrefix().
Get list of registered namespace.
- Returns
- array<string,array<int,string>> List of namesapce prefix / base dir
References $prefixes.
loadClass |
( |
string |
$class | ) |
|
Loads the class file for a given class name.
- Parameters
-
string | $class | The fully-qualified class name |
- Returns
- null|string The mapped file name on success, or null on failure
References $request_count, and loadMappedFile().
Referenced by __construct().
loadMappedFile |
( |
string |
$prefix, |
|
|
string |
$relative_class |
|
) |
| |
|
private |
Load the mapped file for a namespace prefix and relative class.
- Parameters
-
string | $prefix | The namespace prefix |
string | $relative_class | The relative class name |
- Returns
- null|string Null if no mapped file can be loaded, or the name of the mapped file that was loaded
References requireFile().
Referenced by loadClass().
requireFile |
( |
string |
$file | ) |
|
|
private |
If a file exists, require it from the file system.
- Parameters
-
string | $file | The file to require |
- Returns
- bool True if the file exists, false if not
References $loads_count.
Referenced by loadMappedFile().
Get number of loads on this autoloader.
- Returns
- int Number of loads
References $loads_count.
Get number of requests on this autoloader.
- Returns
- int Number of requests
References $request_count.
string DIR_SEP = DIRECTORY_SEPARATOR |
string $root_base_dir = '' |
|
private |
The documentation for this class was generated from the following file: