Module Class
The Module class allows you to easily load, unload, check if a module exists or if it is loaded, or get a list of all modules loaded.
The load method allows you to load one or more modules at runtime. If the module cannot be found a ModuleNotFoundException will be thrown.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$module |
required |
Name of the module to be loaded, or an array of modules. |
$path |
null |
Path to the given module. You can use this to load modules from outside the defined module paths. |
|
Returns |
void |
Example |
Module::load('users');
Module::load('users', '/path/to/modules/users/');
Module::load( array('Users' => '/path/to/modules/users/', 'Groups' => '/path/to/modules/groups/') );
Module::load('awesome');
|
The unload method allows you to unload a module at runtime.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$module |
required |
Name of the module to be unloaded. |
|
Returns |
void |
Example |
Module::unload('users');
|
This will (attempt to) remove all routes that where defined by the module (in its routes.php file) when it was loaded!
The loaded method allows you to check if a module is currently loaded. If no module name is given then all loaded module are returned.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$module |
null |
Name of the module to be checked. |
|
Returns |
bool|array |
Example |
$loaded = Module::loaded('users');
$loaded = Module::loaded();
|
The exists method allows you to check if a module exists, i.e. if it can be found in one of the configured module paths.
If found, it returns the path to the module. If not, it returns false.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$module |
null |
Name of the module to be checked. |
|
Returns |
bool|string |
Example |
if (Module::exists('comments'))
{
Module::load('comments');
}
|