djiele/autoloader

使用PHP tokenizer的另一个类加载器

7.3.1-stable 2020-08-05 10:05 UTC

This package is auto-updated.

Last update: 2024-09-05 19:05:33 UTC


README

这个类在开发不遵循PSR建议的旧库的网站时变得必要。这个类使用PHP tokenizer扩展解析脚本,允许每个文件中找到多个类。命名空间也得到支持。有时候,看到类所在的文件可能会很有用。

安装

您可以通过composer安装此包

composer require djiele/autoloader dev-master
使用方法
// including the class file
require_once 'path/to/class/Autoloader.php';
// or using composer
require_once 'vendor/autoload.php'

use Djiele\PHP\Autoloader;

$autoloaderId = 'my-project-autoloader';
$useCache = true; // true to create/refresh and use generated cache file
$classLoader = new Autoloader($autoloaderId, $useCache); 
$classLoader
    ->setClassMapDir('cache/autoloader') // path to the cache file, created if not exists
    ->setFolders(['src', 'packages']) // array of directories to be analyzed
    ->register() // launch the analyze and register the class in autoload chain
;

就这样!