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.
config/database.php, config/cache.php). The ConfigAggregator enables a declarative, hierarchical merging of these files, aligning with Laravel’s service provider and module patterns..env-driven overrides) maps well to the aggregator’s precedence-based merging (later configs override earlier ones). This reduces boilerplate for environment-specific logic.PhpFileProvider, LaminasConfigProvider) mirrors Laravel’s bind()/singleton() patterns, enabling seamless integration with the container.config/array.php + manual merging) without disrupting existing code.LaminasConfigProvider bridges gaps where Laravel’s built-in config readers fall short (e.g., YAML with custom schemas).laminas-cache) aligns with Laravel’s config_cache optimization, reducing bootstrap time in production.laminas/laminas-config (for non-PHP formats) adds ~5MB to the vendor directory. Mitigate by:
replace or provide to avoid conflicts with Laravel’s vlucas/phpdotenv or symfony/yaml.spatie/flysystem for file-based configs to reduce dependencies.bootstrap/cache/config.php overrides config/) must be explicitly modeled in the aggregator’s provider order. Misconfiguration could lead to silent overrides.PhpFileProvider) add minor CPU overhead during bootstrap. Benchmark against Laravel’s native FileLoader to validate performance.array type hints and ConfigAggregator’s ConfigProviderInterface to enforce structure where critical.config.php → *.local.php → *.env.php) in the aggregator’s provider list?PhpFileProvider('config/*.php') precede PhpFileProvider('config/*.local.php')?config_cache? If so, how will cache invalidation (e.g., config:clear) be handled?.env-based) be integrated? Will a custom provider (e.g., DotEnvProvider) be needed?spatie/laravel-data) as a post-processor to catch misconfigurations early?ConfigRepository during migration? Will a hybrid approach (e.g., aggregator for new configs, native for legacy) be used?Illuminate/Config merging logic. The aggregator’s ConfigAggregator can wrap Laravel’s ConfigRepository or serve as a drop-in replacement for config('key').ConfigAggregatorServiceProvider) that:
Config facade or a new AggregatedConfig facade.config/aggregator.php) for provider definitions.config:cache to use the aggregator’s cache backend.spatie/laravel-config-array: Use the aggregator to merge Spatie’s array configs.laravel/envoy: Leverage the aggregator for remote config management.config('app.providers') with a PhpFileProvider for modular providers.$aggregator = new ConfigAggregator([
new PhpFileProvider(app_path('config/*.php')),
new LaminasConfigProvider(config_path('*.yaml')),
]);
config(['aggregated' => $aggregator->getMergedConfig()]);
ConfigRepository binding to use the aggregator exclusively.laminas/laminas-stdlib for globbing) may be needed.PhpFileProvider works out-of-the-box with Laravel’s file structure.DatabaseProvider) implement __invoke() or extend ConfigProviderInterface.config_cache to avoid conflicts.BootstrapServiceProvider but before RegisterProviders.ConfigAggregatorServiceProvider in config/app.php under providers.config/aggregator.php:
'providers' => [
\App\Providers\CustomConfigProvider::class,
\Laminas\ConfigAggregator\PhpFileProvider::class => [
'paths' => [app_path('config/*.php')],
],
],
$config = app(\Laminas\ConfigAggregator\ConfigAggregator::class)->getMergedConfig();
config:cache to serialize the aggregator’s merged config:
Artisan::command('config:cache', function () {
$aggregator = app(ConfigAggregator::class);
File::put(cache_path('config.php'), '<?php return ' . var_export($aggregator->getMergedConfig(), true) . ';');
});
config/app.php to config/local/app.php).laminas/laminas-config for breaking changes (e.g., YAML parser updates).composer.json if stability is critical.config:dump Artisan command to log the merged config hierarchy for debugging:
Artisan::command('config:dump', function () {
$aggregator = app(ConfigAggregator::class);
foreach ($aggregator->getProviders() as $provider) {
echo get_class($provider) . "\n";
}
echo "Merged:\n" . print_r($aggregator->getMergedConfig(), true);
});
DatabaseProvider, CacheProvider).app.key).How can I help you explore Laravel packages today?