This is a PHP autoload class to load classes dynamically.
Currently, there's no support for namespace
feature which has been added since PHP 5.3 version, but it would be added in the future.
require 'autoload.php';
/**
* AutoLoad::getReady()
*
* Creates an instance of AutoLoad class once
* and returns the instance for later calls
*
* @return object
*/
$loader = AutoLoad::getReady(); // Use $loader or AutoLoad::getReady() itself.
/**
* AutoLoad::fire();
*
* Starts AutoLoading
*/
AutoLoad::getReady()->fire();
require 'autoload.php';
// Get ready, Fire!
AutoLoad::getReady()->addPath('./lib')->addExtension('.class.php')->fire();
// Quick mode:
// Add path while the AutoLoad is getting ready
// This would happen once!
AutoLoad::getReady('./lib')->addExtension('.class.php')->fire();
Parameter | Type | Description |
---|---|---|
$path | string or array |
Path of the class files |
Return Values
(object)
Returns instance of AutoLoad class.
AutoLoad::getReady()->addPath('/path/to/first/directory')
->addPath('/path/to/second/one')
->addPath('/path/to/third');
// OR
$paths = array(
'/path/to/first/directory',
'/path/to/second/one',
'/path/to/third'
);
AutoLoad::getReady()->addPath($paths);
Parameter | Type | Description |
---|---|---|
$path | string or array |
Path of the class files |
Return Values
(object)
Returns instance of AutoLoad class.
AutoLoad::getReady()->removePath('/path/to/first/directory')
->removePath('/path/to/second/one')
->removePath('/path/to/third');
// OR
$paths = array(
'/path/to/first/directory',
'/path/to/second/one',
'/path/to/third'
);
AutoLoad::getReady()->removePath($paths);
Return Values
(array)
Returns all the stored paths.
AutoLoad::getReady()->getPath();
Parameter | Type | Description |
---|---|---|
$extension | string or array |
File extensions of class files. |
Return Values
(object)
Returns instance of AutoLoad class.
AutoLoad::getReady()->addExtension('.inc')
->addExtension('.lib.php')
->addExtension('.class.php');
// OR
$extensions = array('.inc', '.lib.php', '.class.php');
AutoLoad::getReady()->addExtension($extensions);
Parameter | Type | Description |
---|---|---|
$extension | string or array |
File extensions of class files. |
Return Values
(object)
Returns instance of AutoLoad class.
AutoLoad::getReady()->removeExtension('.inc')
->removeExtension('.lib.php')
->removeExtension('.class.php');
// OR
$extensions = array('.inc', '.lib.php', '.class.php');
AutoLoad::getReady()->removeExtension($extensions);
Return Values
(array)
Returns all the stored file extensions.
AutoLoad::getReady()->getExtension();
Parameter | Type | Description |
---|---|---|
$className | string |
The name of the class. |
Return Values
(bool)
Returnsfalse
if the class is not loaded.
AutoLoad::getReady()->isLoaded($className);
Return Values
(array)
Returns an associativearray
containing all the loaded class files.
AutoLoad::getReady()->getLoaded();
Return Values
(void)
Return Values
(void)
// Stop autoloading, Halt!
AutoLoad::getReady()->halt();
$f = new Foo('Err :('); // Fatal error: Class 'Foo' not found in...
// Start it again, Fire!
AutoLoad::getReady()->fire();
$f = new Foo('It Works :)');
Built by @HashemQolami with ♥ and released under the MIT License.
Any suggestions are welcome. create an issue if you have any problems/ideas.
Thanks,
-Hashem Qolami <hashem@qolami.com>