- Can I use symplify/config-transformer to migrate Symfony YAML configs to Laravel’s PHP config format?
- Yes, this package is designed to convert Symfony-style YAML configs into PHP arrays, which Laravel’s config system natively supports. It’s ideal for projects transitioning from Symfony or maintaining hybrid architectures. Place YAML files in a directory (e.g., `config/raw/`) and run the transformer to generate PHP configs in Laravel’s `config/` folder.
- How do I install symplify/config-transformer in a Laravel project?
- Run `composer require symplify/config-transformer --dev` to install it as a development dependency. The package provides a CLI command (`vendor/bin/config-transformer`) to transform configs. Start with `--dry-run` to preview changes before applying them. For Laravel integration, consider adding a custom Artisan command or Composer script to automate the process.
- Does symplify/config-transformer support Laravel-specific config syntax like `env()` placeholders?
- The package handles basic PHP syntax, but Laravel-specific features like `env()` placeholders may require custom transformers. You can extend the default mappings or use the `--skip-routes` flag if you’re migrating incrementally. For complex cases, review the [Symplify documentation](https://github.com/symplify/config-transformer) or create a custom transformer class.
- Will this package break existing Laravel config loaders or service providers?
- No, the package operates on files and doesn’t modify runtime behavior. However, ensure your Laravel config loaders (e.g., `Config::load()` or service providers) are compatible with PHP arrays. Test thoroughly, especially if you use custom config resolvers or dynamic loading logic. The transformed configs will replace YAML/XML files, so validate your application’s config-driven features post-migration.
- Can I use symplify/config-transformer in CI/CD pipelines to auto-generate configs?
- Absolutely. The package is designed for automation—add it to your CI/CD workflow (e.g., GitHub Actions) to transform configs on every push or deploy. Use `--dry-run` in pre-deployment checks to catch issues early. For Laravel, you might also trigger it via a Composer script (e.g., `post-install-cmd`) or a custom Artisan command tied to deployment hooks.
- What Laravel versions does symplify/config-transformer support?
- The package itself is framework-agnostic but works seamlessly with Laravel 8+ due to its PHP-native config system. For older Laravel versions (7.x), ensure your config loaders support PHP arrays. The transformer’s output is compatible with any Laravel version that uses `config/` for configuration, but test edge cases like environment-specific configs or dynamic loading.
- How do I handle circular references or complex YAML structures in Symfony configs?
- Symplify’s transformer leverages Symfony’s `ReferenceNode` handling to manage circular references (e.g., YAML anchors/aliases). For complex structures like nested includes or custom tags, use the `--dry-run` flag to debug issues. If needed, extend the transformer with custom logic or pre-process YAML files to simplify them before transformation.
- Are there alternatives to symplify/config-transformer for converting YAML to PHP in Laravel?
- For Laravel-specific needs, consider `spatie/laravel-config-array` for dynamic config loading or `nunomaduro/collision` for config validation. However, `symplify/config-transformer` is uniquely optimized for Symfony-to-PHP conversions with modular, extensible transformers. If you’re migrating from Symfony or need fine-grained control over the process, this package offers superior flexibility.
- How do I test Laravel applications after transforming YAML configs to PHP?
- Start by testing config-driven features like middleware, queues, or service bindings in isolation. Use PHPUnit to verify that `config('key')` returns expected values. For environment-specific configs (e.g., `.env`-dependent YAML), mock the environment or use Laravel’s `Config::set()` in tests. Validate edge cases like circular dependencies or nested configs with assertions or static analysis tools like PHPStan.
- Can I selectively transform only certain YAML files (e.g., skip routes.yaml) in a Laravel project?
- Yes, use the `--skip-routes` flag or specify file/directory paths as arguments to target specific configs. For example, `vendor/bin/config-transformer config/services.yaml` will only transform `services.yaml`. This is useful for incremental migrations or projects with mixed YAML/PHP configs. Combine with `--dry-run` to preview changes before applying them.