No longer actively maintained. I work now with NodeJS and I recommand you to take a look at di-ninja
Autoload is a simple and concise PHP Autoloader based on universal conventions.
No more need of annoying "require_once" at start of each php file. When needed by php code the class will be dynamicaly loaded and no more load of unused class, increasing performances in same time.
This component is able to autoload all modern PHP frameworks and libraries like Zend, Symfony, PEAR, Aura or many others.
- PSR-4
- PSR-0 (retrocompat)
- classMap API
- include_path support
- HHVM hack
- empty namespace support for root autoload path
- cache for checked class_exists
simple facade API using global instance
use RedCat\Autoload\Autoload;
/* register "MyNamespace\SubSpace" prefix to "myDirectory/src/myNamespacePath" directory */
Autoload::register('myDirectory/src/myNamespacePath','MyNamespace\SubSpace');
/* register the containing file directory as a root directory for autoload */
Autoload::register(__DIR__);
/* equivalent */
Autoload::register(__DIR__,'');
$autoload = Autoload::getInstance();
register and unregister to SPL stack
$autoload->splRegister();
$autoload->splUnregister();
$autoload->addNamespace('Prefix\Of\My\Namespace','target/directory');
$autoload->addNamespace('Prefix\Of\My\Namespace2',[
'target/directory1',
'target/directory2',
]);
$autoload->addNamespaces([
'Prefix\Of\My\Namespace'=>'target/directory/for/my/namespace',
'Prefix\Of\My\Namespace2'=>[
'target/directory1',
'target/directory2',
]
]);
$autoload->useIncludePath(true); //default param to true but default property to false
$autoload->useCache(false); //default param and property to true
$autoload->addClass('My\Class','path/of/myclass.php');
$autoload->addClassMap([
'My\Class'=>'path/of/myclass.php',
'My\Class2'=>'path/of/myclass2.php',
]);