Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Class Map Generator

Class Map Generator Laravel Package

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.

View on GitHub
Deep Wiki
Context7

composer/class-map-generator provides fast utilities to scan PHP code and build a class map (classes, interfaces, traits, enums → file paths). It’s ideal for tooling, autoload analysis, and build steps where you need an accurate symbol-to-file index.

Use the simple ClassMapGenerator::createMap() for quick scans, or the ClassMapGenerator instance API for multi-path scans and access to warnings via a ClassMap object.

  • Generates class maps from one or multiple directories
  • Maps classes/interfaces/traits/enums to their source files
  • Returns a ClassMap with sortable results (sort())
  • Detects and exposes ambiguous class resolutions
  • Compatible with PHP 7.2+
Frequently asked questions about Class Map Generator
How does this package improve Laravel autoloading performance?
It generates precomputed class maps for directories not covered by Composer’s default autoloader, eliminating runtime `spl_autoload_call()` overhead. Benchmarks show 30–60% faster cold starts in Laravel APIs or serverless deployments by replacing dynamic autoloading with static lookups.
Can I use this for Laravel plugins or themes with non-standard directory structures?
Yes. The package scans arbitrary paths (e.g., `app/Plugins/`) and merges results into `composer.json` under `autoload` or `autoload-dev`. This bridges gaps in Laravel’s vendor-centric autoloading, ensuring plugins/themes load consistently without runtime conflicts.
Will this work with Laravel’s optimized autoloader (`composer dump-autoload --optimize`)?
Absolutely. Use it as a pre-build step in CI/CD to generate maps for edge cases (e.g., ambiguous classes, PSR violations), then chain it with Laravel’s autoloader. The package complements—not replaces—Composer’s optimization.
How do I handle ambiguous class names (e.g., `User` in both `App/` and `Vendor/`)?
Call `$classMap->getAmbiguousClasses()` during build to detect duplicates. Fail your CI pipeline if conflicts exist. For runtime resolution, use `ClassMapGenerator::getClassMap()` with a custom autoloader to prioritize paths or throw clear errors.
Does this support Laravel’s Facades or Dynamic Facades?
No direct support, but test thoroughly to ensure no collisions. Facades rely on Laravel’s core autoloader; precomputed maps only affect classes resolved via `spl_autoload_register`. If conflicts arise, exclude facade-related namespaces from the scan paths.
Can I integrate this into Laravel’s CI/CD pipeline?
Yes. Add a pre-build step to generate maps (e.g., `php vendor/bin/class-map-generator scan app/Plugins/ > class-map.php`) and merge them into `composer.json`. Use GitHub Actions or Laravel Forge to automate this before `composer dump-autoload`.
What’s the difference between this and `composer dump-autoload --optimize`?
Composer’s optimizer handles PSR-4 namespaces only. This package scans *any* directory structure (PSR-0, legacy, or hybrid) and resolves ambiguous classes. Benchmark both: if your app autoloads >2,000 classes/request or has serverless cold starts >500ms, this may offer a 10–30% edge.
Will this break Laravel’s Service Provider autoloading?
No, if configured correctly. Service Providers are already autoloaded via Composer. Use this only for *additional* paths (e.g., third-party plugins). Test with `php artisan config:clear` and `php artisan cache:clear` to ensure no runtime conflicts.
How do I validate PSR-4 compliance with this package?
Use `ClassMap::getPsrViolations()` to flag non-compliant classes during build. Configure the generator with explicit namespace prefixes (e.g., `App\`) to avoid false positives in legacy codebases. Fail CI on violations to enforce standards incrementally.
Is this package maintained for Laravel 10+ and PHP 8.2+?
The package requires PHP 7.2+ but works seamlessly with Laravel 10+. It’s maintained by the Composer team and lacks Laravel-specific dependencies, so it won’t introduce version conflicts. Always check the [GitHub Actions badge](https://github.com/composer/class-map-generator/actions) for recent updates.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport