- Can you use symfony/config in a Laravel application?
- Yes. symfony/config is framework-agnostic and Composer-installable with no service provider or container coupling required, so it drops into a Laravel package or module cleanly. It is not a replacement for Laravel's config/ directory or the env() helper; it is a schema layer you wrap around a bounded configuration domain such as a package contract or a multi-source settings store.
- How do I install symfony/config with Composer?
- Run composer require symfony/config and pick the version constraint that matches your PHP floor, for example ^7.4 for the LTS line. The component always pulls symfony/filesystem and symfony/deprecation-contracts. YAML support needs symfony/yaml and XML support needs ext-dom, so if you only load PHP arrays or database rows the dependency footprint stays small.
- Which PHP and Laravel versions does symfony/config support?
- The Symfony 8.x line of this component requires PHP 8.4 or newer, while the 7.4 LTS line runs on PHP 8.2 and up. Because Laravel 11 and 12 applications routinely run PHP 8.2 or 8.3, targeting ^7.4 is the safe choice for most fleets. Check your lowest production PHP version before choosing a constraint, since that floor is the binding constraint on the whole decision.
- What is the difference between symfony/config and Laravel's config:cache?
- Laravel's config:cache is all-or-nothing: any change requires rebuilding the entire cached configuration. symfony/config's ConfigCache tracks individual resources such as files, globs, reflected classes and Composer metadata, so it invalidates only when a specific tracked resource changes. That granularity is the main reason to add the component when you manage configuration outside config/.
- Do I need symfony/yaml or ext-dom to use symfony/config?
- No. YAML and XML loading are opt-in: symfony/yaml is a separate package and XML parsing relies on ext-dom plus XSD validation, both of which you can skip. If your configuration comes from PHP arrays, a database table, or environment values, you can drop both optional dependencies and avoid maintaining XSD schemas. Using only PHP-array and DB loaders keeps the install lean and the upgrade surface small.
- How do I define and validate a configuration schema with TreeBuilder?
- You build a TreeBuilder, declare root and child nodes with NodeBuilder, and call process() on the merged raw values to get normalized, validated output with defaults applied. ArrayNodeDefinition gives you required nodes, enum and numeric constraints, and canBeEnabled() or canBeDisabled() semantics, plus deep-merge rules for nested arrays. The closure DSL is terse and unlike anything in the Laravel ecosystem, so write a short convention document before multiple developers touch it.
- Does ConfigCache invalidate when an environment variable or database row changes?
- No. Resource tracking covers files, globs, classes and Composer metadata, but not environment variables or database rows. A DB-backed settings layer will silently serve stale processed configuration unless you add your own invalidation key, such as a settings version or updated_at timestamp folded into the cache key. Plan for that explicitly rather than assuming the cache tracks everything.
- How do I generate configuration reference documentation with symfony/config?
- Use YamlReferenceDumper or ArrayReferenceDumper against your processed tree to emit a reference of every node, default, allowed value and required flag. This auto-generated output is often the real return on investment, especially for enterprise deployments that need a published, validated config reference for customers or internal teams. It also keeps docs from drifting away from the schema as nodes change.
- Is symfony/config safe to use in production?
- Yes, it is MIT licensed and widely used across the PHP ecosystem, but two operational habits matter. Cached node graphs were not upgrade-safe in some releases, so every deploy should flush the config cache rather than reusing artifacts built by an older version. Also remember env placeholder resolution lives in symfony/dependency-injection, not here, so wire interpolation yourself or accept literal values.
- What are alternatives to symfony/config for validating configuration?
- nette/schema is lighter if you only need schema validation without resource-tracked caching or reference dumpers. Laravel's own Validator and config repository cover app-wide settings well and need no extra dependency. Choose symfony/config when you specifically need multi-format loading, deep-merge semantics and fine-grained cache invalidation for a package or module contract.