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

Config Transformer Laravel Package

symplify/config-transformer

Automates refactoring and normalization of configuration files, helping you transform legacy or inconsistent configs into a unified format. Supports common PHP config styles and streamlines upgrades by applying consistent, repeatable changes across large codebases.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Symfony-to-PHP Config Conversion: Aligns well with modern PHP ecosystems favoring structured, autoloadable configurations (e.g., Symfony, Laravel) over YAML/XML. Reduces runtime parsing overhead and improves IDE support (autocompletion, type hints).
  • Laravel Compatibility: Laravel’s service container and configuration system (e.g., config/) are PHP-native, making this package a natural fit for:
    • Legacy Migration: Converting Symfony-based configs (e.g., from monolithic apps or microservices) into Laravel-compatible PHP arrays.
    • Hybrid Architectures: Projects using Symfony components (e.g., HttpKernel, DependencyInjection) alongside Laravel.
  • Extensibility: The package’s transformer logic is modular, allowing TPMs to:
    • Customize Mappings: Extend or override default YAML-to-PHP conversions (e.g., for Laravel-specific syntax like env() placeholders).
    • Integrate with Packages: Hook into Laravel’s bootstrap/app.php or config.php to auto-transform configs during deployment.

Integration Feasibility

  • Low-Coupling Design: The package operates on files/configs, not runtime objects, minimizing invasive changes.
    • Example Workflow:
      1. Place YAML configs in config/raw/ (e.g., services.yaml).
      2. Run symplify/config-transformer to generate PHP files in config/.
      3. Load PHP configs via Laravel’s Config::load() or service container.
  • Tooling Synergy:
    • CI/CD: Embed in build pipelines (e.g., GitHub Actions) to auto-generate configs on push.
    • Laravel Mix/Vite: Pre-process configs before asset compilation (if configs influence frontend behavior).
  • Database/ORM Impact: Neutral unless configs define migrations or Eloquent models (requires manual validation).

Technical Risk

Risk Area Severity Mitigation
Config Schema Breaks Medium Validate transformed PHP against Laravel’s config/ structure (e.g., use phpstan or custom assertions).
Circular References Low Test with nested YAML configs; leverage Symfony’s ReferenceNode handling.
Performance Overhead Low Benchmark transformation time for large configs (e.g., 100+ files).
Laravel-Specific Quirks Medium Document deviations (e.g., env() placeholders, array syntax) in a README.
Dependency Conflicts Low Isolate package in a dev dependency or custom Composer script.

Key Questions

  1. Use Case Clarity:

    • Is this for one-time migration (e.g., Symfony → Laravel) or ongoing dual-config management?
    • Are configs static (e.g., routes) or dynamic (e.g., user-specific settings)?
  2. Laravel-Specific Needs:

    • Does the project use Symfony’s ParameterBag or Laravel’s config() helper? How will transformed configs map?
    • Are there custom config loaders (e.g., JSON/YAML parsers) that conflict with PHP arrays?
  3. Toolchain Integration:

    • Should the package trigger automatically (e.g., via post-install-cmd) or manually (e.g., php artisan config:transform)?
    • Will configs be version-controlled as PHP or regenerated per-deploy?
  4. Testing Strategy:

    • How will config-driven behavior (e.g., middleware, queues) be tested post-transformation?
    • Are there environment-specific configs (e.g., .env-dependent YAML) requiring special handling?

Integration Approach

Stack Fit

  • PHP/Laravel Ecosystem:
    • Native Support: Laravel’s config/ directory expects PHP arrays, making this a drop-in replacement for YAML/XML.
    • Symfony Interop: If using Symfony components (e.g., FrameworkBundle), configs can remain YAML for those parts while Laravel uses PHP.
  • Tooling Compatibility:
    • Composer: Install as a require-dev dependency or isolate in a custom script.
    • Artisan: Extend with a custom command (e.g., php artisan config:transform) for CLI-driven workflows.
    • IDE: PHPStorm/WebStorm will auto-index transformed configs for refactoring.

Migration Path

  1. Assessment Phase:

    • Audit existing YAML configs for:
      • Complex structures (e.g., anchors, tags) needing custom transformers.
      • Laravel-specific syntax (e.g., env('APP_KEY')) that must be preserved.
    • Example:
      # Before (services.yaml)
      parameters:
        app.path.logs: "%kernel.project_dir%/var/logs"
      
      // After (config/services.php)
      return [
          'parameters' => [
              'app.path.logs' => env('APP_PATH_LOGS', base_path('var/logs')),
          ],
      ];
      
  2. Pilot Migration:

    • Transform a non-critical config (e.g., mail.php) and validate:
      • Runtime behavior (e.g., config('mail.from.address') works).
      • IDE support (autocompletion, type hints).
    • Use --dry-run flag (if available) to preview changes.
  3. Full Rollout:

    • Option A: Incremental:
      • Migrate configs module-by-module (e.g., auth.phpmail.php).
      • Use feature flags to toggle between YAML/PHP sources.
    • Option B: Big Bang:
      • Run transformer in CI before merging to main.
      • Replace config/ entirely with generated PHP files.

Compatibility

  • Laravel Versions:
    • Tested with Laravel 8+ (composer.json constraints).
    • For Laravel <8, may need polyfills for config() helper or Illuminate\Support\Traits\ForwardsCalls.
  • Symfony Components:
    • If using symfony/yaml or symfony/dependency-injection, ensure no conflicts with the transformer’s Symfony\Component\Yaml\Yaml class.
  • Custom Config Loaders:
    • If the project uses spatie/laravel-config-array or similar, document how transformed configs interact with these packages.

Sequencing

  1. Pre-Transformation:

    • Backup config/ directory.
    • Add transformer to composer.json:
      "scripts": {
        "post-install-cmd": [
          "Symplify\\ConfigTransformer\\Command\\TransformCommand"
        ]
      }
      
    • Create a config/raw/ directory for YAML sources.
  2. Transformation:

    • Run:
      composer dump-autoload && vendor/bin/config-transformer transform config/raw config/
      
    • Or integrate into a custom Artisan command:
      // app/Console/Commands/TransformConfigs.php
      use Symplify\ConfigTransformer\ValueObject\Configuration;
      
      protected function handle() {
          $configuration = new Configuration();
          $configuration->addDirectoryToTransform('config/raw');
          $configuration->setOutputDirectory('config');
          $transformer = new Transformer($configuration);
          $transformer->transform();
      }
      
  3. Post-Transformation:

    • Update CI/CD to regenerate configs on config/raw/ changes.
    • Add tests for config-driven logic (e.g., tests/Feature/ConfigTest.php).
    • Deprecate YAML configs via config/raw/README.md:
      WARNING: This directory is deprecated. Use PHP configs in `config/` instead.
      

Operational Impact

Maintenance

  • Pros:
    • Reduced Parsing Overhead: PHP configs eliminate YAML parsing at runtime.
    • Version Control: PHP arrays are easier to diff/merge than YAML (e.g., no indentation issues).
    • Tooling: Native PHP support for static analysis (PSR-12, PHPStan).
  • Cons:
    • Transformer Maintenance: Depend on package updates for YAML schema changes (e.g., Symfony 7+).
    • Custom Logic: Any non-standard YAML (e.g., !custom_tag) requires custom transformers.
  • Mitigation:
    • Pin the package version in composer.json for stability.
    • Document custom transformations in config/README.md.

Support

  • Debugging:
    • Runtime Errors: PHP configs may fail silently (e.g., missing keys). Use Laravel’s config() helper with fallbacks:
      config('services.mailer.host', 'localhost');
      
    • Transformer Issues: Log raw YAML and transformed PHP for diffing:
      vendor/bin/config-transformer debug config/raw/services.yaml
      
  • Rollback Plan:
    • Keep a config/backup/ directory with original YAMLs.
    • Use
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.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views