Nested Validation Attributes (Symfony Blog)

0
55
Conference schedule at SymfonyWorld Online 2021 Summer Edition done twice per day! (Symfony Blog)


Symfony 5.4
is backed by Private Packagist. Private Packagist is a fast, reliable, and secure Composer repository for your private packages. It mirrors all your open-source dependencies for better availability and monitors them for security vulnerabilities.

In Symfony 5.2 we added a feature to define validation constraints as PHP attributes.
Attributes were very recent at that time, because they had just been added to
PHP 8.0. The only caveat was that you couldn’t nest PHP attributes, so you
couldn’t use them with constraints such as AtLeastOneOf and Collection.

Thankfully, PHP 8.1, released on November 25, 2021, adds support for nested
attributes. That’s why in Symfony 5.4 you’ll be able to use PHP attributes to
define all existing constraints, without any exemption.

The trick that enables this feature is to use the new keyword to create the
nested attribute:

This is how it looks in practice when using Symfony Validator constraints in a
complex example:

Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help,
but we also have a wide range of sponsoring opportunities.



Source link

Leave a reply

Please enter your comment!
Please enter your name here