- How do I install and set up craftcms/laravel-aliases in a Laravel 10+ project?
- Run `composer require craftcms/laravel-aliases`, then register the service provider in `AppServiceProvider.php` by adding `$this->app->register(AliasesServiceProvider::class)` to the `register()` method. No additional configuration is needed unless you want to customize default aliases.
- What Laravel versions does this package officially support?
- The package is confirmed compatible with Laravel 10+ (PHP 8.1+). For older Laravel versions, test thoroughly as the package relies on Laravel’s service container and bootstrapping hooks, which may have breaking changes in earlier releases.
- Can I use this package for dynamic runtime aliasing, like switching namespaces based on environment?
- Yes, this package leverages Yii’s `yiisoft/aliases` under the hood, which supports dynamic alias resolution. You can define environment-specific aliases in your Laravel config and resolve them at runtime via the service container.
- Is there a performance impact compared to Laravel’s native autoloader?
- The performance impact is minimal for most use cases. Dynamic alias resolution adds negligible overhead, but in high-throughput systems, benchmark critical paths. For static aliases, Laravel’s native autoloader (PSR-4/classmap) remains more efficient.
- How do I define custom aliases for my Laravel application?
- Add your aliases to the `aliases` array in your Laravel config (e.g., `config/aliases.php`). The package will automatically resolve them through Laravel’s service container. Example: `'aliases' => ['@myplugin' => base_path('plugins/myplugin')]`.
- Will this package work with Yii 2.x modules in a Laravel app?
- Yes, this package is designed for hybrid Yii/Laravel architectures. It bridges Yii’s alias system with Laravel’s container, allowing Yii modules to resolve paths/URLs consistently. Test thoroughly for edge cases like case sensitivity or circular dependencies.
- Are there any known dependency conflicts with popular Laravel packages?
- No known conflicts exist with Laravel’s core or widely used packages (e.g., `laravel/framework`, `illuminate/support`). The package’s sole dependency, `yiisoft/aliases`, is lightweight and isolated from Laravel’s autoloader.
- How should I test alias resolution in my Laravel application?
- Test alias resolution in unit/integration tests by verifying critical paths, such as service container bindings or facade calls. Use Laravel’s `app()` helper to check if aliases resolve correctly (e.g., `app('path.to.alias')`). Mock the `AliasesServiceProvider` if needed.
- What are the risks of using this package if it appears unmaintained?
- The lack of stars/issues/recent activity raises red flags for long-term viability. Risks include undisclosed breaking changes or lack of community support. Mitigate by forking the package or implementing a custom solution (e.g., extending `SplAutoloaderRegister`) if critical.
- Can I replace this package with a custom autoloader solution if needed?
- Yes, if this package proves problematic, you can replace it with a lightweight custom autoloader using `SplAutoloaderRegister` or Laravel’s `ComposerAutoloader::addPsr4()`. Document your custom logic for future maintainers, especially if you rely on dynamic or environment-specific aliases.