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 for classes, interfaces, traits, and enums. Create a quick symbol-to-file map or use the generator for multi-path scans, sorting, and reporting ambiguous class definitions. MIT licensed; PHP 7.2+.

View on GitHub
Deep Wiki
Context7

Utilities to scan PHP code and generate class maps.

Frequently asked questions about Class Map Generator
How does this package improve Laravel autoloading performance compared to `composer dump-autoload`?
This package offers granular control over class discovery, allowing you to pre-generate maps for specific directories (e.g., plugins or modules) without scanning the entire vendor or app directory. Benchmarks show a 30% speedup in scan times (v1.7.3), making it ideal for CLI tools, migrations, or scheduled jobs where autoloading bottlenecks exist. Cache the generated maps in Laravel’s `bootstrap/cache` or Redis for runtime efficiency.
Can I use this for dynamic plugin systems in Laravel where classes are loaded at runtime?
Yes, this package is perfect for dynamic plugins. Scan plugin directories at runtime (e.g., in a `PluginManager` service) and generate class maps on-demand. Use `getAmbiguousClasses()` to handle duplicate class names gracefully, and cache the maps to avoid repeated scans. Example: `$generator->scanPaths(storage_path('plugins'));` in your plugin loader.
Will this work with Laravel’s native autoloading (PSR-4) or do I need to replace it entirely?
It complements Laravel’s autoloading rather than replaces it. Use it for custom paths (e.g., `app/Modules`, `storage/plugins`) while letting Composer handle vendor autoloading. Integrate it into `AppServiceProvider::boot()` or a custom autoloader to merge maps. Avoid scanning `vendor/` or `bootstrap/cache` to prevent conflicts.
How do I handle ambiguous class names (e.g., same class in two plugins) in production?
Use `$classMap->getAmbiguousClasses()` to log warnings during development, then implement a resolution strategy in production (e.g., priority-based loading or explicit namespace prefixes). For plugins, enforce unique namespaces or use a `PluginManager` to route classes dynamically. Test with `getAmbiguousClasses()` in CI to catch issues early.
Is this package compatible with Laravel 10+ and PHP 8.1+? What’s the PHP 7.2 requirement about?
The package requires PHP 7.2+ due to its dependency on Symfony Finder (v5+), but it works seamlessly with Laravel 10+ and PHP 8.1+. For PHP 8.1+ apps, leverage Laravel’s native autoloading for vendor classes and use this package only for custom paths. The PHP 7.2 requirement is a hard limit for the underlying library, not Laravel compatibility.
Can I integrate this into Laravel’s CI/CD pipeline to speed up tests?
Absolutely. Pre-generate class maps in GitHub Actions or GitLab CI before running tests to avoid repeated scans. Use parallel scans for large codebases (e.g., split by directory) and cache results in Redis or the filesystem. Example: Add a `php artisan classmap:generate` command to your CI workflow targeting `app/` and `tests/` directories.
How do I sandbox user-uploaded code to prevent path traversal or malicious scans?
Restrict scans to trusted directories (e.g., `storage/uploads/plugins`) and use exclusion rules to block sensitive paths. Validate paths against a whitelist (e.g., `app_path()`, `storage_path()`) before scanning. Avoid dynamic `eval()` or `create_function()`—this package only scans static files. For extra security, combine with Laravel’s filesystem permissions.
Should I use this for legacy codebases with non-PSR-4 namespaces, or is there a better alternative?
This package excels at handling non-standard namespaces (e.g., legacy `App_Helper` classes) by scanning raw directories. For legacy refactoring, generate maps incrementally (e.g., `app/Modules/`) and migrate namespaces over time. Alternatives like `get_declared_classes()` are slower and don’t support pre-generation. If your legacy code is stable, this is the most maintainable option.
How does this compare to writing a custom autoloader for Laravel?
This package provides a battle-tested, dependency-optimized solution with features like ambiguous class detection and parallel scanning, while a custom autoloader requires more maintenance. Use this for performance-critical paths (e.g., CLI tools) and reserve custom autoloaders for highly specialized cases. It’s also more portable across projects.
Can I use this to optimize Laravel’s `queue:work` or `migrate` commands?
Yes, pre-generate class maps for your queue workers or migrations to eliminate autoloading delays. Cache the maps in Redis or `bootstrap/cache` and load them at runtime. Example: In `AppServiceProvider::boot()`, generate maps for `app/Jobs/` and `database/migrations/` during app startup. This reduces memory usage and speeds up long-running commands.
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor