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.
config/) are PHP-native, making this package a natural fit for:
HttpKernel, DependencyInjection) alongside Laravel.env() placeholders).bootstrap/app.php or config.php to auto-transform configs during deployment.config/raw/ (e.g., services.yaml).symplify/config-transformer to generate PHP files in config/.Config::load() or service container.| 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. |
Use Case Clarity:
Laravel-Specific Needs:
ParameterBag or Laravel’s config() helper? How will transformed configs map?Toolchain Integration:
post-install-cmd) or manually (e.g., php artisan config:transform)?Testing Strategy:
.env-dependent YAML) requiring special handling?config/ directory expects PHP arrays, making this a drop-in replacement for YAML/XML.FrameworkBundle), configs can remain YAML for those parts while Laravel uses PHP.require-dev dependency or isolate in a custom script.php artisan config:transform) for CLI-driven workflows.Assessment Phase:
env('APP_KEY')) that must be preserved.# 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')),
],
];
Pilot Migration:
mail.php) and validate:
config('mail.from.address') works).--dry-run flag (if available) to preview changes.Full Rollout:
auth.php → mail.php).main.config/ entirely with generated PHP files.config() helper or Illuminate\Support\Traits\ForwardsCalls.symfony/yaml or symfony/dependency-injection, ensure no conflicts with the transformer’s Symfony\Component\Yaml\Yaml class.spatie/laravel-config-array or similar, document how transformed configs interact with these packages.Pre-Transformation:
config/ directory.composer.json:
"scripts": {
"post-install-cmd": [
"Symplify\\ConfigTransformer\\Command\\TransformCommand"
]
}
config/raw/ directory for YAML sources.Transformation:
composer dump-autoload && vendor/bin/config-transformer transform config/raw config/
// 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();
}
Post-Transformation:
config/raw/ changes.tests/Feature/ConfigTest.php).config/raw/README.md:
WARNING: This directory is deprecated. Use PHP configs in `config/` instead.
!custom_tag) requires custom transformers.composer.json for stability.config/README.md.config() helper with fallbacks:
config('services.mailer.host', 'localhost');
vendor/bin/config-transformer debug config/raw/services.yaml
config/backup/ directory with original YAMLs.How can I help you explore Laravel packages today?