adachsoft/static-class-finder
Composer 安装命令:
composer require adachsoft/static-class-finder
包简介
A robust, standalone PHP library that resolves the file path of a class based on its Fully Qualified Class Name (FQCN) using only static Composer maps.
README 文档
README
A robust PHP library that resolves the file path of a class based on its Fully Qualified Class Name (FQCN) using only static Composer maps. It also provides an advanced facade (ClassFinder) for searching classes by prefix, partial name, regex, or similarity.
Features
- Static-only resolution: Uses Composer's generated metadata files (
autoload_classmap.php,autoload_psr4.php,autoload_namespaces.php) and never scans the filesystem recursively. - No reflection: Does not load or execute the target class. Safe for files with syntax errors.
- Aggregated sources: Combines multiple static sources (classmap + PSR-4/PSR-0) with deduplicated class names.
- Lazy loading: Loads Composer maps only when needed and caches them in memory.
- Lightweight dependencies: Requires PHP 8.3+ and one runtime dependency (
adachsoft/collection). - Advanced searching: Find classes by namespace prefix, partial name, regular expression, or Levenshtein similarity through the
ClassFinderfacade. - Detailed results: Returns lightweight
ClassLocationDtoobjects with FQCN and an optional relative path (null when the file does not exist anymore).
Installation
composer require adachsoft/static-class-finder
Usage
Basic: Locating a single class
use AdachSoft\StaticClassFinder\Locator;
// Initialize with the root path of the target project (where composer.json lives)
$projectRoot = '/var/www/target-project';
$locator = new Locator($projectRoot);
// Locate a class file
$filePath = $locator->locate('Monolog\Logger');
if ($filePath) {
echo "File found: " . $filePath;
// Output: vendor/monolog/monolog/src/Monolog/Logger.php (relative to project root)
} else {
echo "Class not found.";
}
Advanced: Searching classes
use AdachSoft\StaticClassFinder\ClassFinder;
use AdachSoft\StaticClassFinder\Enum\CaseSensitivityEnum;
use AdachSoft\StaticClassFinder\Enum\MatchTargetEnum;
$classFinder = ClassFinder::create('/var/www/target-project');
// Search by namespace prefix
$results = $classFinder->findByNamespacePrefix('App\\Service');
// Search by partial name (case-insensitive by default)
$results = $classFinder->findByPartialName('User');
// Search by regular expression (on short class name)
$results = $classFinder->findByRegex('/^User/', MatchTargetEnum::SHORT_NAME);
// Search by similarity (Levenshtein distance) on short names
$results = $classFinder->findBySimilarity('UserService', 3);
// Iterate results
foreach ($results as $dto) {
echo $dto->fqcn . ' => ' . ($dto->path ?? 'not found') . PHP_EOL;
}
adachsoft/static-class-finder 适用场景与选型建议
adachsoft/static-class-finder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「autoloader」 「psr-0」 「composer」 「locator」 「PSR-4」 「static-analysis」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 adachsoft/static-class-finder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 adachsoft/static-class-finder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 adachsoft/static-class-finder 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
An package to make it easy to autoload code.
Tune your autoloader
Pop Loader Component for Pop PHP Framework
This composer plugin enables installation of GravityForms WordPress plugin and its addons.
Molajo Resource Services for PHP Applications
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-23