kcs / class-finder
实用类,帮助发现其他类/命名空间
0.5.3
2024-08-30 12:42 UTC
Requires
- php: ^8.1
- thecodingmachine/safe: ^1.0 || ^2.0
Requires (Dev)
- doctrine/annotations: ^1.0
- phpbench/phpbench: ^1.2
- phpdocumentor/reflection: ^4.0 || ^5.0 || ^6.0
- phpunit/phpunit: ^10.5
- roave/better-reflection: ^6.0
- roave/security-advisories: dev-master
- solido/php-coding-standards: dev-master
- symfony/cache: ^5.0 || ^6.0 || ^7.0
- symfony/error-handler: ^5.0 || ^6.0 || ^7.0
README
实用类,帮助发现其他类/命名空间
安装
$ composer require kcs/class-finder
使用
Finder 帮助您在项目中发现类。
最常见的方法是使用提供的 ComposerFinder
。这将使用 composer 自动生成的类加载器搜索类,并相应地解析 PSR-* 命名空间。
在 https://alekitto.github.io/class-finder/ 的文档中了解更多信息
基本用法
use Kcs\ClassFinder\Finder\ComposerFinder; $finder = new ComposerFinder(); foreach ($finder as $className => $reflector) { // Do magic things... }
过滤
您可以使用 FinderInterface
提供的方法来过滤类
implementationOf(array $interfaces)
: 找到实现所有给定接口的类。您可以传递一个接口作为字符串。subclassOf(string $superClass)
: 找到给定类的所有子类。annontatedBy(string $annotationClass)
: 找到在类文档块中具有给定注解的所有类。withAttribute(string $attributeClass)
: 仅查找具有给定属性应用于类的所有类(PHP >= 8.0)。in(array $dirs)
: 仅在给定的目录中搜索。inNamespace(array $namespaces)
: 仅在给定的命名空间中搜索。filter(callable $callback)
: 自定义过滤回调。pathFilter(callable $callback)
: 加载文件的自定义过滤回调。
许可证
此库在 MIT 许可证下发布。
贡献
我们始终欢迎贡献。请随时打开 PR 或提交问题。
感谢阅读
A.