\Hazaar
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(); $loader->loadController('index');

p(notice notice-info) . 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.

p(notice notice-warning) . Instantiating this class directly can have undefined results.

Tags

Since

1.0.0

Summary
Methods Properties Constants
No constants
Properties
$application
$application
Static
$instance
$instance
$paths
$paths
Methods
__construct()
__construct($application)
Initialise a new loader

p(notice notice-warning) . Do NOT instantiate this class directly. See Loader::getInstance() on how to get a new Loader instance.

Parameters

$application

No description

addIncludePath()
addIncludePath($path)

Parameters

$path

No description

addSearchPath()
addSearchPath($type, $path)

Add a new search path for loading classes from library files

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.

Tags

Since

1.0.0

Parameters

$typestring

The path type to add.

$pathstring

The path to add.

addSearchPaths()
addSearchPaths($array)

Add multiple search paths from an array

Tags

Since

1.0.0

Parameters

$array\Array

Array containing type/path pairs.

Static
fixDirectorySeparator()
fixDirectorySeparator($path)

Parameters

$path

No description

Static
getClassSource()
getClassSource($path)

Check the library paths to make sure the file exists somewhere

Tags

Since

1.0.0

Parameters

$path

No description

Static
getFilePath()
getFilePath($type, $search_file = null, $base_path = 'application_path', $case_insensitive = false) : string

Return the absolute filesystem path to a file. By default this method uses the application path as the base path.

This method also checks that the file exists. If the file does not exist then null will be returned.

Tags

Since

1.0.0

Parameters

$typestring

The path type to search. See Loader::addSearchPath()

$search_file

No description

$base_pathstring

The path to use as a search base if there are no paths of the requested

   	type.
$case_insensitiveboolean

By default paths are case sensitive. In some circumstances this might

   	not
   	be desirable so set this TRUE to perform a(slower)case insensitive
   	search.

Returns

string

The absolute path to the file if it exists. NULL otherwise.

Static
getInstance()
getInstance($application = null)

Return the current instance of the Loader object.

Tags

Since

1.0.0

Parameters

$application\Application

The current application instance

Static
getModuleFilePath()
getModuleFilePath($search_file = null, $module = null, $case_insensitive = false)

Parameters

$search_file

No description

$module

No description

$case_insensitive

No description

getSearchPaths()
getSearchPaths($type = null) : Array

Return an array of search paths for this loader instance

Tags

Since

1.0.0

Parameters

$type

No description

Returns

\Array

Array of search paths

Static
isAbsolutePath()
isAbsolutePath($path)

Parameters

$path

No description

Static
loadClassFromFile()
loadClassFromFile($class_name)

Loads a class from a source file. This is the main class loader used by the __autoload()PHP trigger. It is responsible for loading the files that hold class source definitions by determining the correct file to load based on the class name.

First check if the class name is a single word that ends with 'Controller', designating it as a controller class. If that matches then the class is loaded from the controller path.

Otherwise we check if the class starts with Application and load from the application path.

Lastly we do a 2 stage search of the library paths. Stage 1 looks for a correlating path while stage 2 looks for the class in a sub-directory of the module name.

We do 2 stage class path checking.

If they both fail, the class is not found and we throw a pretty exception.

Parameters

$class_namestring

The name of the class to load.

loadController()
loadController($controller) : mixed

This method is used to load a new instance of a controller class. There are some built-in 'magic controllers' that this method will automatically load upon request.

These controllers are:

If no controller can be found the default site controller will be loaded.

Tags

Since

1.0.0

Parameters

$controllerstring

The name of the controller to load. This can be style or script to

   	load Style and Script controllers.

Returns

mixed

A controller instance (\Hazaar\Application\Controller) or FALSE.

register()
register()

Register this loader instance as a class autoloader

Tags

Since

1.0.0

Static
resolve()
resolve($filename) : string

Resolve a filename within any of the search paths

Tags

Since

1.0.0

Parameters

$filename

No description

Returns

string

Absolute path to the file

Static
resolveRealPath()
resolveRealPath($filename, $case_insensitive = false)

Parameters

$filename

No description

$case_insensitive

No description

setApplication()
setApplication($application)

Parameters

$application

No description

setSearchPath()
setSearchPath($type, $path) : boolean
Sets the search path for a file type

This is the same as addSearchPath except that it overwrites any existing paths.

Tags

Since

2.3.3

Parameters

$typemixed

The path type to add.

$pathmixed

The path to add.

Returns

boolean
unregister()
unregister()

Unregister this loader instance as a class autoloader

Tags

Since

1.0.0