Skip to content

Conversation

@MatTheCat
Copy link
Contributor

Q A
Branch? 7.4
Bug fix? no
New feature? no
Deprecations? yes
Issues N/A
License MIT

Split from #60568

@MatTheCat
Copy link
Contributor Author

high-deps failure seems related to #61101; how could it be fixed?

@MatTheCat MatTheCat force-pushed the deprecate_validator_xml_loader branch 2 times, most recently from d89cbc6 to 2efe806 Compare August 3, 2025 12:00
@xabbuh
Copy link
Member

xabbuh commented Aug 3, 2025

As written in #60568 (comment) I don't think it's worth doing this for the Validator component. Maintaining the XmlFileLoader is not much work.

@javiereguiluz @OskarStark @wouterj Do you think getting rid of the XML format would make the life for Symfony docs that much easier that dropping support for it would be worth it?

@alexandre-daubois
Copy link
Member

Writing XML config in the docs was a real pain until Copilot is a thing. Last time I checked, Copilot (and other tools) are extremely efficient for that.

@stof
Copy link
Member

stof commented Aug 29, 2025

I think this might be too early to do that deprecation in 7.4, as the suggested replacement API (#61528) will be shipped only in 7.4 as well. This would make it hard for bundles to migrate to the new API while keeping support for multiple Symfony versions.

I suggest delaying that deprecation until some 8.x release (the maintenance cost of this XmlFileLoader is not an issue regarding maintaining it for 2 more years IMO, as it has basically not changed since years)

nicolas-grekas added a commit that referenced this pull request Sep 3, 2025
…time constraint metadata (nicolas-grekas)

This PR was merged into the 7.4 branch.

Discussion
----------

[Validator] Allow using attributes to declare compile-time constraint metadata

| Q             | A
| ------------- | ---
| Branch?       | 7.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Issues        | -
| License       | MIT

Prerequisite for #61288

At the moment, validation attributes are read at runtime when `framework.validation.enable_attributes` is true.

This means they don't fit for bundles nor can't they be warmed up.

This PR fixes both issues by using a new `validator.attribute_metadata` resource tag, that's turned into a list of classes to parse for attributes at compile-time.

For apps, the tag is added by autoconfiguration: any `Constraint`-derived attributes found on a class in the `src/` folder will trigger the rule to add the tag.

For bundles (and for apps if they want to), the tag is added by explicit service configuration. In an "eat your own dog-food" spirit, this capability is used to declare the constraints of the `Form` class: instead of loading the `validation.xml` file, we now declare this service resource:
```php
        ->set('validator.form.attribute_metadata', Form::class)
            ->tag('container.excluded')
            ->tag('validator.attribute_metadata')
```

This reads the attributes added to the `Form` class:
```php
#[AssertForm()]
#[Traverse(false)]
class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterface
```

Bundles can do the same and replace their XML files by attributes.

As a next step, we could also deprecate runtime-discovery of attributes. This could be worth it if this discovery has a measurable performance impact. To be measured if one wants to dig this idea.

Side note: I'm hoping this could allow removing the yaml and xml config formats one day. For serialization metadata also (PR coming). BUT, this doesn't (yet) cover the use case of overriding metadata defined by bundles. For that, apps still have to use xml or yaml in config/validation/. I have an idea to cover this, coming to a next PR if it works.

(failures unrelated)

Commits
-------

0197b50 [Validator] Allow using attributes to declare compile-time constraint metadata
@nicolas-grekas
Copy link
Member

Let me close for reasons explained in #61288 (comment).
A big thank you for pushing this forward, it made us realize that we have some more steps ahead before being able to deprecate.
But I definitely want to reconsider on 8.x!

@MatTheCat MatTheCat deleted the deprecate_validator_xml_loader branch September 4, 2025 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants