Loader
Loader
Global class file loader.
This class contains methods for auto-loading classes from files in the Hazaar library path. Ordinarily there will be no need for developers to use this class directly but it does contain a few methods for working with paths and library files.
This class is not meant to be instantiated directly and instances should be retrieved using the Loader::getInstance()method.
Example
$loader = Hazaar\Loader::getInstance();
!!! notice The loader class is loaded automatically when starting the application. There should be no need to use the Loader instance directly and static methods have been provided for some extra functionality.
!!! warning Instantiating this class directly can have undefined results.
Properties
paths
public array $paths
applicationPath
private string $applicationPath
instances
private array $instances
Methods
__construct
Initialise a new loader.
protected __construct(string $applicationPath): void
!!! warning Do NOT instantiate this class directly. See Loader::getInstance() on how to get a new Loader instance.
Parameters
Parameter | Type | Description |
---|---|---|
$applicationPath | string |
getInstance
public getInstance(string $path): Loader
Parameters
Parameter | Type | Description |
---|---|---|
$path | string |
register
Register this loader instance as a class autoloader.
public register(): void
unregister
Unregister this loader instance as a class autoloader.
public unregister(): void
addIncludePath
public addIncludePath(string $path): void
Parameters
Parameter | Type | Description |
---|---|---|
$path | string |
addSearchPath
Add a new search path for loading classes from library files.
public addSearchPath(FilePath $type, string $path): void
The path type can be anything if you are using the loader to load your own library files. There are built in path types for loading Hazaar library files.
- FilePath::ROOT - Path that contains the whole project
- FilePath::MODEL - Path contains model classes
- FilePath::VIEW - Path contains view files.
- FilePath::CONTROLLER - Path contains controller classes.
- FilePath::SUPPORT - Path contains support files. Used by the Application::runDirect()method.
- FilePath::CONFIG - Configuration files
Parameters
Parameter | Type | Description |
---|---|---|
$type | FilePath | the path type to add |
$path | string | the path to add |
setSearchPath
Sets the search path for a file type.
public setSearchPath(mixed $type, mixed $path): void
This is the same as addSearchPath except that it overwrites any existing paths.
Parameters
Parameter | Type | Description |
---|---|---|
$type | mixed | the path type to add |
$path | mixed | the path to add |
addSearchPaths
Add multiple search paths from an array.
public addSearchPaths(array $array): void
Parameters
Parameter | Type | Description |
---|---|---|
$array | array | Array containing type/path pairs |
getSearchPaths
Return an array of search paths for this loader instance.
public getSearchPaths(?FilePath $type): void
Parameters
Parameter | Type | Description |
---|---|---|
$type | FilePath |
isAbsolutePath
public isAbsolutePath(string $path): bool
Parameters
Parameter | Type | Description |
---|---|---|
$path | string |
getFilePath
public getFilePath(FilePath $type, ?string $searchFile): ?string
Parameters
Parameter | Type | Description |
---|---|---|
$type | FilePath | |
$searchFile | string |
resolve
public resolve(string $filename): ?string
Parameters
Parameter | Type | Description |
---|---|---|
$filename | string |
loadClassFromFile
public loadClassFromFile( $className): void
Parameters
Parameter | Type | Description |
---|---|---|
$className | `````` |
Generated by Hazaar API Doc Generator