承接 liquidrazor/class-locator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

liquidrazor/class-locator

Composer 安装命令:

composer require liquidrazor/class-locator

包简介

Minimal deterministic class discovery and validation library for PHP 8.3+.

README 文档

README

A minimal PHP 8.3+ library for deterministic class discovery and validation.

What it does

  • Uses liquidrazor/file-locator to discover PHP files
  • Maps file paths → FQCN using PSR-4 rules
  • Validates that your codebase matches its declared structure
  • Exposes structural symbol metadata from declared symbols when declaration validation runs

That’s it.

Philosophy

  • Filesystem is truth
  • Deterministic mapping over guesswork
  • Validation is explicit, not implicit
  • No magic, no hidden loading
  • Built for real-world broken projects

Dependency Model

ClassLocator is built on top of:

  • liquidrazor/file-locator

It does NOT define roots.
It consumes whatever FileLocator provides.

Namespace Resolution

ClassLocator does NOT detect namespaces for discovery.

Instead:

  1. Namespace roots are loaded from the target project's composer.json (PSR-4)
  2. File paths are mapped deterministically to expected FQCN
  3. Namespace parsing is used for validation and structural metadata extraction when enabled by mode

Filesystem + Composer define expectation.
Files must comply.

Modes

ENFORCING (default)

  • Requires valid Composer PSR-4 mappings
  • Validates all files
  • Extracts structural metadata from declared symbols
  • Throws on critical violations
  • Fails fast on broken structure

STRICT

  • Validates all files
  • Extracts structural metadata from declared symbols
  • Collects violations
  • Does not throw

LENIENT

  • Best-effort discovery
  • Skips invalid entries
  • Skips declaration validation
  • Returns unresolved structural metadata instead of guessing

Validation

Validation compares:

expected (path + composer)
vs
actual (file namespace + symbol)

Detects:

  • Namespace mismatch
  • Class/interface/trait/enum mismatch
  • Files outside PSR-4 scope
  • Duplicate FQCN
  • Missing or invalid Composer mappings

Usage

$fileLocator = new FileLocator(...);

$classLocator = new ClassLocator($fileLocator, Mode::STRICT);

$result = $classLocator->locate();

Public API

ClassLocator

new ClassLocator(FileLocator $fileLocator, Mode $mode = Mode::ENFORCING)
LocateResult locate()

Mode (enum)

Mode::ENFORCING
Mode::STRICT
Mode::LENIENT

LocateResult

array getClasses()
array getViolations()
bool hasViolations()

SymbolKind (enum)

SymbolKind::CLASS_
SymbolKind::INTERFACE
SymbolKind::TRAIT
SymbolKind::ENUM

SymbolKind::CLASS_ uses a trailing underscore because CLASS collides with PHP's ::class constant syntax.

ClassInfo

string getFqcn()
string getPath()
?SymbolKind getSymbolKind()
array getImplementedInterfaces()
?string getParentClass()
?bool isAbstract()
?bool isFinal()
bool hasResolvedMetadata()

In ENFORCING and STRICT, ClassInfo metadata is derived from the declared symbol in the source file.

In LENIENT, declaration parsing is skipped, so:

  • getSymbolKind() returns null
  • getImplementedInterfaces() returns []
  • getParentClass() returns null
  • isAbstract() returns null
  • isFinal() returns null
  • hasResolvedMetadata() returns false

Violation

string getMessage()
string getPath()

Example: Inspect Structural Metadata

$fileLocator = new FileLocator(...);
$classLocator = new ClassLocator($fileLocator, Mode::STRICT);

$result = $classLocator->locate();

foreach ($result->getClasses() as $classInfo) {
    if (!$classInfo->hasResolvedMetadata()) {
        continue;
    }

    if ($classInfo->getSymbolKind() !== SymbolKind::CLASS_) {
        continue;
    }

    if (in_array('App\\Contract\\EventSubscriber', $classInfo->getImplementedInterfaces(), true)) {
        // Downstream code can classify this symbol without re-parsing the file.
    }
}

Responsibility Boundary

ClassLocator exposes structural symbol metadata.

It still does NOT:

  • classify framework concepts
  • register services
  • detect event semantics
  • manipulate autoloading
  • execute discovered files

Downstream tools may use the exposed metadata for their own classification or validation logic.

Summary

Give it a FileLocator.

It gives you deterministic classes, structural violations, and source-derived symbol metadata when validation is enabled.

liquidrazor/class-locator 适用场景与选型建议

liquidrazor/class-locator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「composer」 「validation」 「PSR-4」 「class-discovery」 「class-locator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 liquidrazor/class-locator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 liquidrazor/class-locator 我们能提供哪些服务?
定制开发 / 二次开发

基于 liquidrazor/class-locator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 23
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-27