A minimal PHP 8.3+ library for deterministic class discovery and validation.
- Uses
liquidrazor/file-locatorto discover PHP files - Maps file paths → FQCN using PSR-4 rules
- Validates that your codebase matches its declared structure
That’s it.
- Filesystem is truth
- Deterministic mapping over guesswork
- Validation is explicit, not implicit
- No magic, no hidden loading
- Built for real-world broken projects
ClassLocator is built on top of:
liquidrazor/file-locator
It does NOT define roots.
It consumes whatever FileLocator provides.
ClassLocator does NOT detect namespaces for discovery.
Instead:
- Namespace roots are loaded from
composer.json(PSR-4) - File paths are mapped deterministically to expected FQCN
- Namespace parsing is used ONLY for validation (depending on mode)
Filesystem + Composer define expectation.
Files must comply.
- Requires valid Composer PSR-4 mappings
- Validates all files
- Throws on critical violations
- Fails fast on broken structure
- Validates all files
- Collects violations
- Does not throw
- Best-effort discovery
- Skips invalid entries
- Minimal validation
Validation compares:
expected (path + composer)
vs
actual (file namespace + symbol)
- Namespace mismatch
- Class/interface/trait/enum mismatch
- Files outside PSR-4 scope
- Duplicate FQCN
- Missing or invalid Composer mappings
$fileLocator = new FileLocator(...);
$classLocator = new ClassLocator($fileLocator);
$result = $classLocator->locate();new ClassLocator(FileLocator $fileLocator, Mode $mode = Mode::ENFORCING)LocateResult locate()Mode::ENFORCING
Mode::STRICT
Mode::LENIENTarray getClasses()
array getViolations()
bool hasViolations()string getFqcn()
string getPath()string getMessage()
string getPath()- No DI
- No service registration
- No autoload manipulation
- No file execution
- No framework coupling
Give it a FileLocator.
It gives you classes.
If your project is lying, it tells you.