- 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.