Wallogit.com
2017 © Pedro Peláez
JetFire - Autoload support PSR-4 convention
A PSR-4 autoloader., (*1)
Via composer, (*2)
composer require jetfirephp/autoload
To use the autoloader, first instantiate it, then register it with SPL autoloader stack:, (*3)
require_once __DIR__ . '/vendor/autoload.php'; $loader = new \JetFire\Autoloader\Autoload(); $loader->register();
To add a single namespace here how to do this :, (*4)
$loader->addNamespace('App\Admin','/path/to/app-admin/src');
$loader->addNamespace('App\Admin','/path/to/app-admin/tests');
For multiple namespaces :, (*5)
$loader->setNamespaces([
'App\Admin' => [
'/path/to/app-admin/src',
'/path/to/app-admin/tests'
],
'App\Public' => '/path/to/app-public'
]);
// or
$loader->setNamespaces('/path/to/namespaces/file.php');
This will override all previous namespace settings., (*6)
To map a class to a file, use the addClass() method., (*7)
$loader->addClass('App/Admin/Auth','/path/to/app-admin/Auth.php');
For multiple classes :, (*8)
$loader->setClassCollection([
'App\Admin\Auth' => '/path/to/app-admin/Auth.php'
]);
// or
$loader->setClassCollection('path/to/classes/file.php');
If you set a default base directory for your autoloader like this :, (*9)
$loader = new \JetFire\Autoloader\Autoload('/path/to/base/directory');
And you want to instantiate a class Auth.php with the namespace App\Admin when you have not define this namespace in addClass() method, JetFire\Autoloader will check if the file Auth.php exists in /path/to/base/directory/App/Admin/ folder., (*10)
The JetFire Autoloader is released under the MIT public license : http://www.opensource.org/licenses/MIT., (*11)