Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laminas Config Aggregator Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Modular Configuration Management: The package excels in Laravel’s modular architecture, where configurations are often split across multiple files (e.g., 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.
  • Environment-Specific Overrides: Laravel’s support for environment-specific configs (e.g., .env-driven overrides) maps well to the aggregator’s precedence-based merging (later configs override earlier ones). This reduces boilerplate for environment-specific logic.
  • Integration with Laravel’s Service Container: The aggregator’s ability to inject providers (e.g., PhpFileProvider, LaminasConfigProvider) mirrors Laravel’s bind()/singleton() patterns, enabling seamless integration with the container.

Integration Feasibility

  • Low Friction: The package’s standalone nature (no Laravel-specific dependencies) allows for gradual adoption. A TPM could introduce it as a replacement for Laravel’s native config merging (e.g., config/array.php + manual merging) without disrupting existing code.
  • Format Agnosticism: Supports PHP, JSON, YAML, XML, and INI, which covers Laravel’s primary config formats. The LaminasConfigProvider bridges gaps where Laravel’s built-in config readers fall short (e.g., YAML with custom schemas).
  • Caching: The aggregator’s built-in caching (via laminas-cache) aligns with Laravel’s config_cache optimization, reducing bootstrap time in production.

Technical Risk

  • Dependency Bloat: Introducing laminas/laminas-config (for non-PHP formats) adds ~5MB to the vendor directory. Mitigate by:
    • Using Composer’s replace or provide to avoid conflicts with Laravel’s vlucas/phpdotenv or symfony/yaml.
    • Leveraging Laravel’s existing spatie/flysystem for file-based configs to reduce dependencies.
  • Precedence Complexity: Laravel’s config precedence (e.g., bootstrap/cache/config.php overrides config/) must be explicitly modeled in the aggregator’s provider order. Misconfiguration could lead to silent overrides.
  • Generator Overhead: Generators (e.g., PhpFileProvider) add minor CPU overhead during bootstrap. Benchmark against Laravel’s native FileLoader to validate performance.
  • Type Safety: PHP arrays lack runtime type checking. Use PHP 8.2’s array type hints and ConfigAggregator’s ConfigProviderInterface to enforce structure where critical.

Key Questions

  1. Provider Ordering:
    • How will the TPM enforce Laravel’s precedence rules (e.g., config.php*.local.php*.env.php) in the aggregator’s provider list?
    • Example: Should PhpFileProvider('config/*.php') precede PhpFileProvider('config/*.local.php')?
  2. Caching Strategy:
    • Will the aggregator’s cache replace Laravel’s config_cache? If so, how will cache invalidation (e.g., config:clear) be handled?
  3. Environment Awareness:
    • How will environment-specific configs (e.g., .env-based) be integrated? Will a custom provider (e.g., DotEnvProvider) be needed?
  4. Validation:
    • Should the TPM add schema validation (e.g., via spatie/laravel-data) as a post-processor to catch misconfigurations early?
  5. Legacy Compatibility:
    • How will the aggregator coexist with Laravel’s ConfigRepository during migration? Will a hybrid approach (e.g., aggregator for new configs, native for legacy) be used?
  6. Testing:
    • What test coverage is needed for provider precedence, edge cases (e.g., circular dependencies), and performance under high config volume?

Integration Approach

Stack Fit

  • Laravel Core: Replaces or augments Laravel’s Illuminate/Config merging logic. The aggregator’s ConfigAggregator can wrap Laravel’s ConfigRepository or serve as a drop-in replacement for config('key').
  • Service Providers: Integrate via a custom provider (e.g., ConfigAggregatorServiceProvider) that:
    • Registers the aggregator as a singleton.
    • Binds it to Laravel’s Config facade or a new AggregatedConfig facade.
    • Publishes config files (e.g., config/aggregator.php) for provider definitions.
  • Artisan Commands: Extend Laravel’s config:cache to use the aggregator’s cache backend.
  • Package Ecosystem: Complements packages like:
    • spatie/laravel-config-array: Use the aggregator to merge Spatie’s array configs.
    • laravel/envoy: Leverage the aggregator for remote config management.

Migration Path

  1. Phase 1: Opt-In for New Features
    • Introduce the aggregator for non-critical configs (e.g., third-party packages).
    • Example: Replace config('app.providers') with a PhpFileProvider for modular providers.
  2. Phase 2: Hybrid Integration
    • Use the aggregator alongside Laravel’s native config:
      $aggregator = new ConfigAggregator([
          new PhpFileProvider(app_path('config/*.php')),
          new LaminasConfigProvider(config_path('*.yaml')),
      ]);
      config(['aggregated' => $aggregator->getMergedConfig()]);
      
  3. Phase 3: Full Replacement
    • Override Laravel’s ConfigRepository binding to use the aggregator exclusively.
    • Deprecate manual config merging in favor of provider-based definitions.

Compatibility

  • Laravel Versions:
    • Tested on Laravel 10+ (PHP 8.1+). For older versions, polyfills (e.g., laminas/laminas-stdlib for globbing) may be needed.
  • Provider Compatibility:
    • Native Providers: PhpFileProvider works out-of-the-box with Laravel’s file structure.
    • Third-Party Providers: Ensure providers (e.g., DatabaseProvider) implement __invoke() or extend ConfigProviderInterface.
    • Caching: Align cache keys with Laravel’s config_cache to avoid conflicts.
  • Bootstrap Timing: The aggregator should run after Laravel’s BootstrapServiceProvider but before RegisterProviders.

Sequencing

  1. Bootstrap:
    • Register the ConfigAggregatorServiceProvider in config/app.php under providers.
    • Define providers in config/aggregator.php:
      'providers' => [
          \App\Providers\CustomConfigProvider::class,
          \Laminas\ConfigAggregator\PhpFileProvider::class => [
              'paths' => [app_path('config/*.php')],
          ],
      ],
      
  2. Runtime:
    • Use the aggregator in service providers or facades:
      $config = app(\Laminas\ConfigAggregator\ConfigAggregator::class)->getMergedConfig();
      
  3. Cache:
    • Extend 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) . ';');
      });
      

Operational Impact

Maintenance

  • Provider Management:
    • Pros: Centralized config definitions reduce duplication (e.g., no more copying config/app.php to config/local/app.php).
    • Cons: Provider misconfiguration (e.g., incorrect glob patterns) can break the entire config system. Mitigate with:
      • Runtime validation (e.g., check if all provider files exist).
      • IDE support (e.g., PHPStorm’s glob pattern validation).
  • Dependency Updates:
    • Monitor laminas/laminas-config for breaking changes (e.g., YAML parser updates).
    • Pin versions in composer.json if stability is critical.
  • Debugging:
    • Add a 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);
      });
      

Support

  • Onboarding:
    • Document provider ordering rules (e.g., "local configs must come after global").
    • Provide templates for common providers (e.g., DatabaseProvider, CacheProvider).
  • Troubleshooting:
    • Common issues:
      • Silent Overrides: Later providers overwriting critical keys (e.g., app.key).
      • Missing Files: Glob patterns failing due to permissions or paths.
      • Caching Issues: Stale cache after config changes.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata