diff --git a/reference/constraints/All.rst b/reference/constraints/All.rst index 1577a07ec4d..f50efb5bf0d 100644 --- a/reference/constraints/All.rst +++ b/reference/constraints/All.rst @@ -39,6 +39,23 @@ entry in that array: protected $favoriteColors = []; } + .. code-block:: php-attributes + + // src/Entity/User.php + namespace App\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + // IMPORTANT: nested attributes requires PHP 8.1 or higher + class User + { + #[Assert\All([ + new Assert\NotBlank, + new Assert\Length(min: 5), + ])] + protected $favoriteColors = []; + } + .. code-block:: yaml # config/validator/validation.yaml @@ -93,6 +110,11 @@ entry in that array: } } +.. versionadded:: 5.4 + + The ``#[All]`` PHP attribute was introduced in Symfony 5.4 and requires + PHP 8.1 (which added nested attribute support). + Now, each entry in the ``favoriteColors`` array will be validated to not be blank and to be at least 5 characters long. diff --git a/reference/constraints/AtLeastOneOf.rst b/reference/constraints/AtLeastOneOf.rst index fb29a86f8d8..28f55ede51c 100644 --- a/reference/constraints/AtLeastOneOf.rst +++ b/reference/constraints/AtLeastOneOf.rst @@ -60,6 +60,31 @@ The following constraints ensure that: protected $grades; } + .. code-block:: php-attributes + + // src/Entity/Student.php + namespace App\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + // IMPORTANT: nested attributes requires PHP 8.1 or higher + class Student + { + #[Assert\AtLeastOneOf([ + new Assert\Regex('/#/'), + new Assert\Length(min: 10), + ])] + protected $plainPassword; + + #[Assert\AtLeastOneOf([ + new Assert\Count(min: 3), + new Assert\All( + new Assert\GreaterThanOrEqual(5) + ), + ])] + protected $grades; + } + .. code-block:: yaml # config/validator/validation.yaml @@ -149,6 +174,11 @@ The following constraints ensure that: } } +.. versionadded:: 5.4 + + The ``#[AtLeastOneOf]`` PHP attribute was introduced in Symfony 5.4 and + requires PHP 8.1 (which added nested attribute support). + Options ------- diff --git a/reference/constraints/Collection.rst b/reference/constraints/Collection.rst index c60679aa90b..0f249c1d818 100644 --- a/reference/constraints/Collection.rst +++ b/reference/constraints/Collection.rst @@ -88,6 +88,35 @@ following: ]; } + .. code-block:: php-attributes + + // src/Entity/Author.php + namespace App\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + // IMPORTANT: nested attributes requires PHP 8.1 or higher + class Author + { + #[Assert\Collection( + fields: [ + 'personal_email' => new Assert\Email, + 'short_bio' => [ + new Assert\NotBlank, + new Assert\Length( + max: 100, + maxMessage: 'Your short bio is too long!' + ) + ] + ], + allowMissingFields: true, + )] + protected $profileData = [ + 'personal_email' => '...', + 'short_bio' => '...', + ]; + } + .. code-block:: yaml # config/validator/validation.yaml @@ -162,6 +191,11 @@ following: } } +.. versionadded:: 5.4 + + The ``#[Collection]`` PHP attribute was introduced in Symfony 5.4 and + requires PHP 8.1 (which added nested attribute support). + Presence and Absence of Fields ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/reference/constraints/Sequentially.rst b/reference/constraints/Sequentially.rst index da7bd16f4b2..9e6f6eaefbb 100644 --- a/reference/constraints/Sequentially.rst +++ b/reference/constraints/Sequentially.rst @@ -67,6 +67,27 @@ You can validate each of these constraints sequentially to solve these issues: public $address; } + .. code-block:: php-attributes + + // src/Localization/Place.php + namespace App\Localization; + + use App\Validator\Constraints as AcmeAssert; + use Symfony\Component\Validator\Constraints as Assert; + + // IMPORTANT: nested attributes requires PHP 8.1 or higher + class Place + { + #[Assert\Sequentially([ + new Assert\NotNull, + new Assert\Type('string'), + new Assert\Length(min: 10), + new Assert\Regex(Place::ADDRESS_REGEX), + new AcmeAssert\Geolocalizable, + ])] + public $address; + } + .. code-block:: yaml # config/validator/validation.yaml @@ -128,6 +149,11 @@ You can validate each of these constraints sequentially to solve these issues: } } +.. versionadded:: 5.4 + + The ``#[Sequentially]`` PHP attribute was introduced in Symfony 5.4 and + requires PHP 8.1 (which added nested attribute support). + Options ------- pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy