- How does this package improve Laravel autoloading performance?
- It precomputes class maps during build time, reducing runtime autoloading latency by 30–50%. This is especially useful for serverless Laravel (AWS Lambda/Bref) where cold starts are critical. The package integrates with Laravel’s `composer dump-autoload --optimize` while offering finer control.
- Can I use this for hybrid PSR-0 and PSR-4 autoloading in Laravel?
- Yes, the package supports mixed autoloading setups, making it ideal for legacy Laravel codebases or third-party plugins that don’t follow PSR-4. You can scan multiple paths and enforce PSR compliance selectively using `clearPsrViolationsByPath()`.
- How do I integrate this into my Laravel project?
- Add it to `composer.json` under `require`, then use it in a `post-autoload-dump` script. For example: `'scripts': { 'post-autoload-dump': ['Composer\ClassMapGenerator\ClassMapGenerator::createMap("app")'] }`. This runs automatically after `composer dump-autoload`.
- Will this work with Laravel 10+ and PHP 8.5+?
- Yes, the package supports PHP 7.2+ and has fixes for PHP 8.5+ compatibility (v1.7.2+). Laravel 10+ (PHP 8.2+) will work seamlessly, though you may need to adjust namespace handling for newer PHP features like enums or attributes.
- How do I handle ambiguous class names (e.g., same class in multiple paths)?
- The package detects ambiguous classes via `getAmbiguousClasses()` and provides warnings. You can resolve conflicts manually or exclude problematic paths during scanning. For Laravel, this is useful when merging third-party code with your app’s namespace.
- Is this better than Laravel’s built-in `composer dump-autoload --optimize`?
- It offers more granular control—like excluding directories, enforcing PSR compliance, or handling legacy PSR-0 code. Use it if you need fine-tuned autoloading (e.g., for plugins or mixed setups) or want to precompute maps in CI/CD for serverless deployments.
- Can I use this in CI/CD to speed up deployments?
- Absolutely. Precompute class maps in your CI pipeline (e.g., GitHub Actions) as a build step. This reduces deployment-time autoloading overhead, which is critical for serverless Laravel where cold starts must be minimized. Store the generated map in cache for reuse.
- Does this work with Laravel’s service providers or package autoloading?
- Yes, it integrates with Laravel’s autoloader by replacing or extending Composer’s autoloading rules. For packages, scan their vendor paths during build time to avoid runtime conflicts. Example: `$generator->scanPaths(base_path('vendor/package/src'))`.
- How do I test if this package actually improves performance?
- Use profiling tools like Blackfire or Xdebug to measure autoloading latency before/after integration. Focus on cold-start metrics in serverless environments. The package’s `getClassMap()` method also provides warnings about PSR violations or ambiguous classes that could affect performance.
- Are there alternatives if I don’t need advanced features?
- For simple projects, Laravel’s default `composer dump-autoload --optimize` may suffice. Alternatives include `vlucas/php5-skeleton` for minimal setups or `symfony/finder` for custom path scanning. However, this package is uniquely suited for hybrid autoloading, legacy code, or serverless optimizations.