league / construct-finder
查找类、接口、特质和枚举。
1.4.0
2024-08-29 07:24 UTC
Requires
- php: ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~7.4.0
Requires (Dev)
- phpstan/phpstan: ^1.3
- phpunit/phpunit: ^9.5
README
这个库可以帮助你定位PHP代码中的类、接口、特质和枚举。构造查找器可以定位目录中所有代码结构。
安装
composer require league/construct-finder
使用
查找构造
你可以查找所有构造或者使用特定类型的查找器。
use League\ConstructFinder\ConstructFinder; // Find all constructs $constructs = ConstructFinder::locatedIn(__DIR__ . '/SomeDirectory')->findAll(); $constructNames = ConstructFinder::locatedIn(__DIR__ . '/SomeDirectory')->findAllNames(); // Find all classes $constructs = ConstructFinder::locatedIn(__DIR__ . '/SomeDirectory')->findClasses(); $constructNames = ConstructFinder::locatedIn(__DIR__ . '/SomeDirectory')->findClassNames() // Find all interfaces $constructs = ConstructFinder::locatedIn(__DIR__ . '/SomeDirectory')->findInterfaces(); $constructNames = ConstructFinder::locatedIn(__DIR__ . '/SomeDirectory')->findInterfaceNames(); // Find all enums $constructs = ConstructFinder::locatedIn(__DIR__ . '/SomeDirectory')->findEnums(); $constructNames = ConstructFinder::locatedIn(__DIR__ . '/SomeDirectory')->findEnumNames(); // Find all traits $constructs = ConstructFinder::locatedIn(__DIR__ . '/SomeDirectory')->findTraits(); $constructNames = ConstructFinder::locatedIn(__DIR__ . '/SomeDirectory')->findTraitNames();
使用构造
构造是简单的值对象,暴露了名称和类型。
use League\ConstructFinder\Construct; use League\ConstructFinder\ConstructFinder; // Find all constructs $constructs = ConstructFinder::locatedIn(__DIR__ . '/SomeDirectory')->findAll(); /** @var Construct $construct */ $construct = $constructs[0]; $name = $construct->name(); $name = (string) $construct; $type = $construct->type(); // class, trait, interface, enum
在多个目录中查找
一次性提供多个目录进行搜索。
use League\ConstructFinder\ConstructFinder; // Find all constructs $constructs = ConstructFinder::locatedIn( __DIR__ . '/SomeDirectory', __DIR__ . '/AnotherDirectory', )->findAll();
基于排除模式排除文件
所有模式都匹配完整。你可以使用通配符(*
)进行模糊匹配。
use League\ConstructFinder\ConstructFinder; // Find all constructs $constructs = ConstructFinder::locatedIn(__DIR__ . '/SomeDirectory') ->exclude('*Test.php', '*/Tests/*') ->findAll();