Package Class
The Package class allows you to easily load, unload, check if a package is loaded, or get all packages loaded.
load($package, $path = null)
The load method allows you to load one or more packages at runtime. If the package cannot be found a PackageNotFoundException will be thrown.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$package |
required |
Name of the package to be loaded, or an array of packages and package paths. |
$path |
PKGPATH |
Path to the folder in which the package is installed. |
|
Returns |
void |
Example |
// load the orm package
Package::load('orm');
// load the parser package from a specific directory
Package::load('parser', '/path/to/packages/dir/');
// load multiple packages from a single package installation
Package::load( array('First' => PKGPATH.'my'.DS.'first'.DS, 'Last' => PKGPATH.'my'.DS.'last'.DS) );
// load the non-existent package
Package::load('awesome'); // Throws a PackageNotFoundException
|
unload($package)
The unload method allows you to unload a package at runtime.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$package |
required |
Name of the package to be unloaded. |
|
Returns |
void |
Example |
// unload the orm package
Package::unload('orm');
|
loaded($package = null)
The loaded method allows you to check if a package is currently loaded. If no package name is given then all loaded packages are returned.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$package |
null |
Name of the package to be checked. |
|
Returns |
bool|array |
Example |
// Check if the orm package is loaded
$loaded = Package::loaded('orm');
// Get all loaded packages
$loaded = Package::loaded();
/*
Returns something like:
array(
'orm' => '/path/to/orm',
'parser' => '/path/to/parser',
)
*/
|