bartlomiejbeta/di-env-loader-bundle
Pros:
DIEnvLoaderTrait), enabling modular adoption without forcing architectural changes.dev, test, prod), useful for Laravel’s .env-based environments.Cons:
register(), boot()) and config caching, while this bundle targets Symfony’s Extension + ContainerBuilder.config/environments/ or config/APP_ENV.php conventions.Extension-based bundles.ContainerBuilder with Laravel’s Container.mergeConfigFrom() or loadEnvironmentConfigs() to integrate.App::environment() or config('app.env') would replace self::getEnv().ContainerBuilder API has evolved (e.g., ParameterBag deprecations in Symfony 5+).symfony/yaml).config/APP_ENV.php (Laravel 5.5+).config/environments/ directory (community packages like spatie/laravel-environment-config).ContainerBuilder is not cached by default; Laravel’s config:cache may conflict.| Component | Fit Level | Notes |
|---|---|---|
| Laravel DI | ❌ Poor | Bundle uses Symfony’s ContainerBuilder; Laravel’s Container is incompatible. |
| YAML Configs | ✅ Good | Laravel supports YAML via spatie/laravel-yaml-config. |
| Environment Detection | ✅ Good | Laravel’s App::environment() mirrors Symfony’s kernel env logic. |
| Service Providers | ⚠️ Medium | Requires wrapping the bundle in a Laravel provider to bridge APIs. |
| Config Loading | ⚠️ Medium | Would need to extend Laravel’s ConfigRepository or mergeConfigFrom. |
config/services.php, config/database.php).DIEnvLoaderServiceProvider) that:
ContainerBuilder calls to Laravel’s Container.register() to load configs via loadByEnv().use DIEnvLoaderBundle\DIEnvLoaderTrait;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class DIEnvLoaderServiceProvider extends ServiceProvider {
use DIEnvLoaderTrait;
public function register() {
$loader = new YamlFileLoader($this->app, new FileLocator(__DIR__.'/config'));
self::loadByEnv($loader, $this->app, 'services', 'yml');
}
}
config/environments/ (or a custom path).config/app.php to include the provider.php artisan config:clear + php artisan serve).symfony/dependency-injection (v3.x). Laravel’s symfony/console (v5.x+) may conflict.services.yml).dev and test environments.config:cache may need bypassing).AppServiceProvider or environment files.services-{env}.yml convention.spatie/laravel-environment-config as an alternative.ContainerBuilder is not optimized for Laravel’s lazy loading. May increase boot time.| Scenario | Impact | Mitigation Strategy |
|---|---|---|
Missing services-{env}.yml |
ConfigError (app crash) | Add file_exists() checks or graceful fallbacks. |
| Invalid YAML syntax | ParseError (app crash) | Validate YAML before loading (e.g., with Symfony\Component\Yaml\Yaml::parse). |
| Symfony/Laravel DI conflict | Undefined method calls | Isolate the bundle in a separate container or use reflection. |
| PHP 8.x deprecations | Runtime errors | Patch the bundle or fork it. |
| Config caching conflicts | Stale configs | Clear cache (php artisan config:clear) or bypass caching for dynamic configs. |
How can I help you explore Laravel packages today?