Class robot loader
Class robot loader for find and require class.
Installation
The preferred way to install this extension is through composer.
$ composer require braunmar/classloader
Or add:
"braunmar/classloader": "*"
To the require
section of your composer.json file. Then rune:
$ composer update
Examples
Just simple use:
braunmar\simple\classloader\ClassLoader::getInstance()
->addDir(__DIR__ . '/../vendor')
->addDir(__DIR__ . '/../libs')
->register();
Or use with cache:
$cache = new braunmar\simple\cache\SimpleCache();
$cache->setType('json')
->setMinify(true);
braunmar\simple\classloader\ClassLoader::getInstance()
->addDir(__DIR__)
->setCache($cache)
->register();
Note:
You must require files with SimpleCache()
and ClassLoader()
classes first.
Methods
The class supports these methods:
addDir
Add directory to, where robot loader try to find classes.
ClassLoader::getInstance()
->addDir(__DIR__);
addDirs
Add directories, where robot loader try to find classes. Same as addDir, but for arrays.
ClassLoader::getInstance()
->addDirs([__DIR__, __DIR__ . '/vendor']);
addIgnoreDir
Add directory, which robot loader ignore when try to find classes.
ClassLoader::getInstance()
->addIgnoreDir('.git');
addIgnoreDirs
Add directories, which robot loader ignore when try to find classes.
ClassLoader::getInstance()
->addIgnoreDirs(['.git', 'sometrash']);
getInstance
Get currect instance.
$instance = ClassLoader::getInstance();
register
Register (enable) robot loader.
ClassLoader::getInstance()
->addDir(__DIR__)
->register();
setCache
Set cache class for store finded class. Class must implement methods load()
and cache($data)
.
ClassLoader::getInstance()
->setCache($cache);
unregister
Unregister (disable) robot loader.
ClassLoader::getInstance()
->unregister();
Licence
Class robot loader is under MIT licence. See the LICENSE
for details.