redcatphp / autoload
This package is abandoned and no longer maintained.
No replacement package was suggested.
Autoload - Simple and Concise PHP Autoloader - PSR-4 convention
v2.3.2
2017-03-16 13:31 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2020-01-24 16:01:33 UTC
README
No longer actively maintained. I work now with NodeJS and I recommand you to take a look at di-ninja
Autoload - PHP native dependency manager
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
Methods usage
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__,'');
get global instance
$autoload = Autoload::getInstance();
register and unregister to SPL stack
$autoload->splRegister(); $autoload->splUnregister();
add namespaces
$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', ] ]);
useIncludePath
$autoload->useIncludePath(true); //default param to true but default property to false
useCache
$autoload->useCache(false); //default param and property to true
addClass and addClassMap
$autoload->addClass('My\Class','path/of/myclass.php'); $autoload->addClassMap([ 'My\Class'=>'path/of/myclass.php', 'My\Class2'=>'path/of/myclass2.php', ]);