composer/class-map-generator
Generate PHP class maps by scanning directories to map classes/interfaces/traits/enums to file paths. Use a simple static helper or an advanced generator to scan multiple paths, sort results, and detect ambiguous class resolutions.
composer dump-autoload --optimize is insufficient.bootstrap/app.php or register() to avoid runtime scans.composer dump-autoload via a custom command (e.g., php artisan classmap:generate).file, redis, database) for zero-cost autoloading in subsequent requests.vendor/, critical for Laravel’s plugin/theme ecosystems or monorepos.composer require composer/class-map-generator).ClassMapGenerator::createMap('path/to/src') for one-off use cases.ClassMapGenerator to scan multiple paths, filter namespaces, and handle ambiguities.ClassMapGenerator instance as a singleton.Illuminate\Foundation\Bootstrap\LoadConfiguration or Illuminate\Foundation\Bootstrap\RegisterProviders.Illuminate\Cache\Events\CacheMissed or Illuminate\Filesystem\Events\FileUpdated.| Risk | Mitigation | Severity |
|---|---|---|
| Ambiguous Classes | Use getAmbiguousClasses() to log warnings during build time; fail fast in CI if ambiguities exist. |
Medium |
| PSR Violations | Leverage getPsrViolations() to enforce namespace compliance in CI (e.g., block PRs with violations). |
Low |
| Path Normalization | Test cross-platform paths (Windows/Linux) early; use realpath() for consistency. |
Low |
| Performance Overhead | Benchmark against composer dump-autoload --optimize; ensure generation time is amortized over deployments (e.g., CI precompute). |
Medium |
| Dependency Bloat | Minimal footprint (no Symfony Finder required post-1.7.0); MIT license avoids vendor lock-in. | Low |
| Laravel Cache Sync | Implement a ClassMapCache class extending Laravel’s Cache to invalidate maps on file changes. |
Medium |
| Stream Wrapper Issues | Test with zip://, phar://, or custom wrappers; fallback to filesystem if unsupported. |
Low |
composer dump-autoload entirely, or augment it for specific paths (e.g., plugins)?post-install-cmd, or a custom Artisan command?)ClassMapGenerator scale?App, Vendor) for granular caching?composer install or vendor updates?ComposerAutoloader::getInitializer() with a custom loader using precomputed maps.file, redis, database).Illuminate\Foundation\Bootstrap\Registered or Illuminate\Events\Dispatcher.composer.json autoload rules; can override or supplement them.zip://, phar://, or custom wrappers (tested in 1.6.0+).classmap:generate command for manual triggers.| Phase | Action | Tools |
|---|---|---|
| Assessment | Profile autoloading bottlenecks with Blackfire or Xdebug; identify paths where static maps would help. | Blackfire, Xdebug |
| Pilot | Generate maps for a non-critical module (e.g., plugins, legacy code); compare performance against composer dump-autoload. |
ClassMapGenerator, Benchmark |
| Core Integration | Replace composer dump-autoload for specific paths (e.g., app/Plugins) using a custom Artisan command. |
Artisan, composer.json |
| Full Adoption | Migrate entire autoloader to use precomputed maps; invalidate caches on file changes. | Laravel Cache, File Events |
| CI/CD Optimization | Precompute maps in CI and cache them for deployments; add validation for PSR violations/ambiguities. | GitHub Actions, PHPUnit |
| Monitoring | Track autoloading time via Laravel Telescope or custom metrics; alert on map generation failures. | Telescope, Prometheus |
ClassMapGenerator as a service.autoload-dev or autoload.composer require composer/class-map-generator.ClassmapGenerateCommand) to generate maps.ComposerAutoloader::getInitializer() with a custom loader using precomputed maps.cache:classmap.php).composer dump-autoload --optimize.FileUpdated event).How can I help you explore Laravel packages today?