mouf/classname-mapper
mouf/classname-mapper is a lightweight PHP utility for mapping class names to custom identifiers, making it easier to resolve aliases and decouple configuration from concrete class strings. Useful for DI containers, plugin registries, and flexible component lookup.
require classes at boot, or do we resolve and compile ahead of time?"opcache.preload generation, container compilation, or eliminating boot-time scans, this package is prior art for the file-resolution half of that work.extra.laravel.providers auto-discovery for internal packages; plugin registries in a multi-tenant product.Adopt the idea freely; adopt the package only under narrow conditions.
Consider it (or a vendored copy) when:
require-ing files.Look elsewhere when:
| Need | Better fit |
|---|---|
| Maintained, Composer-official resolution semantics | composer/class-map-generator (extracted from Composer 2.4) |
| Parse file contents (attributes, docblocks, types) | nikic/php-parser, roave/better-reflection |
| Laravel-idiomatic package auto-discovery | Laravel's built-in provider discovery + a small Finder scan |
| Runtime performance | Generate a static classmap in CI; don't resolve per-request |
Avoid it outright if you require PHP 8.1+ attribute/enum awareness, a security-response process, or a dependency you can put in front of an auditor. The low opportunity signal is not a flaw in the problem — it's a signal that this is a small primitive, not a product. Any competent engineer can reimplement it in a day.
To executives (one paragraph): This is not a dependency request. It's a design pattern worth roughly half a day of engineering. The capability — mapping a class name to a file without loading it — is what lets us move expensive boot-time class scanning into a build step, cutting per-request work. The package itself is stale (last release 2019, no downstream users), so the recommendation is to lift the approach, not the code. Cost is negligible; the benefit is a measurably faster and more predictable boot path.
To engineering (the actual ask): We need reliable class-to-file resolution for a set of PSR-4 roots so we can compile discovery artifacts (container bindings, registered drivers, preload lists) instead of reflecting at runtime. The candidate package demonstrates the API but is effectively abandoned — no PHP 8.1 assurance, no security process, zero dependents. Two acceptable paths: (1) adopt composer/class-map-generator, which is the maintained equivalent with matching resolution semantics, or (2) write a ~150-line adapter if we need control over caching, error handling, and namespace filtering. Recommend a one-day spike against path (1) with path (2) as fallback. Do not add mouf/classname-mapper to composer.json.
How can I help you explore Laravel packages today?