laminas/laminas-config-aggregator
Aggregate and merge configuration from multiple providers in Laminas/Mezzio apps. Supports ordered loading, caching, PHP/array and glob-based config files, and environment-specific overrides for fast, predictable configuration builds.
env('APP_ENV') === 'local' ? LocalDbProvider::class : ProductionDbProvider::class).config() helper or environment variables (e.g., .env values) into merged configs.ConfigCacheProvider) directly addresses Laravel’s bootstrap performance needs, especially in production. This reduces I/O overhead during bootstrap/app.php execution.config/, config/caching.php).config:publish for package-specific configs).deploy.php generating config/deploy.php).ConfigRepository with a ConfigAggregator-backed facade.ConfigLoader to use ConfigAggregator for merging.ConfigAggregator as a singleton.spatie/laravel-yaml-frontmatter) and extends to INI/XML if needed.register() and merge configs in boot().PhpFileProvider for config/{env}.php files.config/caching.php by caching the merged output.| Risk Area | Mitigation Strategy |
|---|---|
| Breaking Changes | Laravel’s config system is stable; the package’s API is mature (last release: 2026). |
| Performance Overhead | Benchmark getMergedConfig() vs. Laravel’s native loader. Cache aggressively. |
| Format Incompatibilities | Test edge cases (e.g., nested arrays, duplicate keys) with Laravel’s config validation. |
| Dependency Bloat | Only pull in laminas/laminas-config if using non-PHP formats (JSON/YAML/XML). |
| Debugging Complexity | Use ConfigAggregator::getProviders() to inspect the merge order during development. |
config() helper and ConfigRepository?
ConfigAggregator to maintain backward compatibility.config:cache command to cache the aggregated output?
ConfigPublisher to use ConfigAggregator..env) be handled?
.env values into the merged config.config:publish for packages?
PhpFileProvider with correct precedence.CallableProvider that queries the DB and returns an array.Illuminate\Config\ConfigLoader and ConfigRepository.Vendor\Package\ConfigProvider).config/app.php) with ConfigAggregator.Illuminate\Foundation\Bootstrap\LoadConfiguration to use ConfigAggregator.config/caching.php to cache the merged output.ConfigAggregatorServiceProvider for Laravel packages.class MyPackageConfig implements ConfigProviderInterface).ConfigAggregator.config:aggregate Artisan command for validation.| Component | Compatibility Notes |
|---|---|
| Laravel 10+ | Full support; leverages PHP 8.1+ features (e.g., named arguments). |
| Laravel Packages | Packages can opt-in via ConfigAggregatorServiceProvider. |
| Environments | Supports .env-driven dynamic providers (e.g., env('APP_ENV') ? LocalProvider::class : null). |
| Cached Configs | Aligns with Laravel’s config:cache by caching the merged array. |
| Legacy Code | Backward-compatible via facade; no breaking changes to config('key'). |
ConfigAggregator in bootstrap/app.php before ConfigRepository is loaded.$aggregator = new ConfigAggregator([
new PhpFileProvider(__DIR__.'/../config/*.php'),
new LaminasConfigProvider(__DIR__.'/../config/*.{json,yaml}'),
new EnvProvider(), // Custom provider for .env
]);
$config = new ConfigRepository($aggregator->getMergedConfig());
register() and merge configs in boot().public function boot()
{
$this->app->singleton(ConfigAggregator::class, function () {
return new ConfigAggregator([
new PhpFileProvider(config_path('*.php')),
new PackageConfigProvider($this->app->loadedProviders()),
]);
});
}
app(ConfigAggregator::class)->getMergedConfig() for dynamic access.config/caching.php:
return [
'aggregated' => app(ConfigAggregator::class)->getMergedConfig(),
];
database.php) without touching others.config/*.php).ConfigAggregator alongside Laravel’s native system during migration.config:validate Artisan command to check for missing/duplicate providers.config('key') as before.CallableProvider).config/caching.php (Laravel’s existing mechanism).PhpFileProvider) to avoid loading all files upfront.ConfigAggregator vs. Laravel’s native loader for large configs (e.g., 100+ files).ConfigAggregator is stateless; safe for concurrent requests.How can I help you explore Laravel packages today?