wwtg99 / class_loader
0.1.1
2016-07-19 10:43 UTC
Requires
- php: >=5.6
- symfony/class-loader: ~3.0
Requires (Dev)
- phpunit/phpunit: ~5.2
This package is not auto-updated.
Last update: 2024-09-14 19:04:12 UTC
README
描述
使用命名空间自动加载类文件。基于Symfony Psr4ClassLoader。
用法
如果目录如下所示
- src
- TestClass
- Test1.php (类 Test1,命名空间 TestClass)
- Sub
- Test2.php (类 Test2,命名空间 TestClass\Sub)
- TestClass
$register_path =[
['TestClass', 'TestClass', true], //[prefix, path, recursive], directory with first letter upper case will be loaded recursively.
];
$loader = new \ClassLoader\Loader(*path_to_src*, $register_path);
$loader->autoload();
// Class Test1 and Test2 do not need require
$test1 = new \TestClass\Test1();
$test2 = new \TestClass\Sub\Test2();