From eed27a02fe8198a28c86c359ce4b31cb84171780 Mon Sep 17 00:00:00 2001 From: Romain Monteil Date: Fri, 12 Aug 2022 09:42:58 +0200 Subject: [PATCH] Replace Assert annotations with attributes, remove Assert annotation configuration block --- form/embedded.rst | 10 +- forms.rst | 21 ---- reference/constraints/All.rst | 18 ---- reference/constraints/AtLeastOneOf.rst | 28 ------ reference/constraints/Bic.rst | 15 --- reference/constraints/Blank.rst | 15 --- reference/constraints/Callback.rst | 37 +------ reference/constraints/CardScheme.rst | 18 ---- reference/constraints/Choice.rst | 54 ---------- reference/constraints/Cidr.rst | 15 --- reference/constraints/Collection.rst | 51 +++------- reference/constraints/Compound.rst | 43 +------- reference/constraints/Count.rst | 20 ---- reference/constraints/Country.rst | 15 --- reference/constraints/CssColor.rst | 34 ------- reference/constraints/Currency.rst | 15 --- reference/constraints/Date.rst | 16 --- reference/constraints/DateTime.rst | 16 --- reference/constraints/DivisibleBy.rst | 22 ----- reference/constraints/Email.rst | 17 ---- reference/constraints/EqualTo.rst | 22 ----- reference/constraints/Expression.rst | 60 ----------- .../constraints/ExpressionLanguageSyntax.rst | 22 ----- reference/constraints/File.rst | 19 ---- reference/constraints/GreaterThan.rst | 67 ------------- reference/constraints/GreaterThanOrEqual.rst | 67 ------------- reference/constraints/Hostname.rst | 15 --- reference/constraints/Iban.rst | 17 ---- reference/constraints/IdenticalTo.rst | 22 ----- reference/constraints/Image.rst | 38 ------- reference/constraints/Ip.rst | 15 --- reference/constraints/IsFalse.rst | 20 ---- reference/constraints/IsNull.rst | 15 --- reference/constraints/IsTrue.rst | 20 ---- reference/constraints/Isbn.rst | 18 ---- reference/constraints/Isin.rst | 15 --- reference/constraints/Issn.rst | 15 --- reference/constraints/Json.rst | 17 ---- reference/constraints/Language.rst | 15 --- reference/constraints/Length.rst | 20 ---- reference/constraints/LessThan.rst | 67 ------------- reference/constraints/LessThanOrEqual.rst | 67 ------------- reference/constraints/Locale.rst | 17 ---- reference/constraints/Luhn.rst | 15 --- reference/constraints/Negative.rst | 15 --- reference/constraints/NegativeOrZero.rst | 15 --- reference/constraints/NotBlank.rst | 15 --- .../constraints/NotCompromisedPassword.rst | 15 --- reference/constraints/NotEqualTo.rst | 22 ----- reference/constraints/NotIdenticalTo.rst | 22 ----- reference/constraints/NotNull.rst | 15 --- reference/constraints/Positive.rst | 15 --- reference/constraints/PositiveOrZero.rst | 15 --- reference/constraints/Range.rst | 73 -------------- reference/constraints/Regex.rst | 52 ---------- reference/constraints/Sequentially.rst | 24 ----- reference/constraints/Time.rst | 16 --- reference/constraints/Timezone.rst | 15 --- reference/constraints/Traverse.rst | 15 --- reference/constraints/Type.rst | 33 ------- reference/constraints/Ulid.rst | 15 --- reference/constraints/Unique.rst | 15 --- reference/constraints/Url.rst | 66 ------------- reference/constraints/UserPassword.rst | 17 ---- reference/constraints/Uuid.rst | 15 --- reference/constraints/Valid.rst | 57 ----------- validation.rst | 99 +------------------ validation/custom_constraint.rst | 23 +---- validation/groups.rst | 27 ----- validation/sequence_provider.rst | 72 -------------- validation/severity.rst | 25 ----- validation/translations.rst | 15 --- 72 files changed, 21 insertions(+), 1967 deletions(-) diff --git a/form/embedded.rst b/form/embedded.rst index 156b8a7a767..901f9ea6275 100644 --- a/form/embedded.rst +++ b/form/embedded.rst @@ -24,9 +24,7 @@ creating the ``Category`` class:: class Category { - /** - * @Assert\NotBlank - */ + #[Assert\NotBlank] public $name; } @@ -38,10 +36,8 @@ Next, add a new ``category`` property to the ``Task`` class:: { // ... - /** - * @Assert\Type(type="App\Entity\Category") - * @Assert\Valid - */ + #[Assert\Type(type: Category::class)] + #[Assert\Valid] protected $category; // ... diff --git a/forms.rst b/forms.rst index 6edffafa232..f1246282efa 100644 --- a/forms.rst +++ b/forms.rst @@ -469,27 +469,6 @@ object. .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Task.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Task - { - /** - * @Assert\NotBlank - */ - public $task; - - /** - * @Assert\NotBlank - * @Assert\Type("\DateTime") - */ - protected $dueDate; - } - .. code-block:: php-attributes // src/Entity/Task.php diff --git a/reference/constraints/All.rst b/reference/constraints/All.rst index 20317136983..30d71bbebfc 100644 --- a/reference/constraints/All.rst +++ b/reference/constraints/All.rst @@ -18,24 +18,6 @@ entry in that array: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/User.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class User - { - /** - * @Assert\All({ - * @Assert\NotBlank, - * @Assert\Length(min=5) - * }) - */ - protected $favoriteColors = []; - } - .. code-block:: php-attributes // src/Entity/User.php diff --git a/reference/constraints/AtLeastOneOf.rst b/reference/constraints/AtLeastOneOf.rst index 42067f0c231..8b400c66dd1 100644 --- a/reference/constraints/AtLeastOneOf.rst +++ b/reference/constraints/AtLeastOneOf.rst @@ -22,34 +22,6 @@ The following constraints ensure that: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Student.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Student - { - /** - * @Assert\AtLeastOneOf({ - * @Assert\Regex("/#/"), - * @Assert\Length(min=10) - * }) - */ - protected $password; - - /** - * @Assert\AtLeastOneOf({ - * @Assert\Count(min=3), - * @Assert\All( - * @Assert\GreaterThanOrEqual(5) - * ) - * }) - */ - protected $grades; - } - .. code-block:: php-attributes // src/Entity/Student.php diff --git a/reference/constraints/Bic.rst b/reference/constraints/Bic.rst index 0f041e4a26f..7cc2e46f558 100644 --- a/reference/constraints/Bic.rst +++ b/reference/constraints/Bic.rst @@ -20,21 +20,6 @@ will contain a Business Identifier Code (BIC). .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Transaction.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Transaction - { - /** - * @Assert\Bic - */ - protected $businessIdentifierCode; - } - .. code-block:: php-attributes // src/Entity/Transaction.php diff --git a/reference/constraints/Blank.rst b/reference/constraints/Blank.rst index b09156296f2..fe17e88e40f 100644 --- a/reference/constraints/Blank.rst +++ b/reference/constraints/Blank.rst @@ -27,21 +27,6 @@ of an ``Author`` class were blank, you could do the following: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Blank - */ - protected $firstName; - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/reference/constraints/Callback.rst b/reference/constraints/Callback.rst index bf9f14b29e4..fd30933e89f 100644 --- a/reference/constraints/Callback.rst +++ b/reference/constraints/Callback.rst @@ -28,25 +28,6 @@ Configuration .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - use Symfony\Component\Validator\Context\ExecutionContextInterface; - - class Author - { - /** - * @Assert\Callback - */ - public function validate(ExecutionContextInterface $context, $payload) - { - // ... - } - } - .. code-block:: php-attributes // src/Entity/Author.php @@ -178,20 +159,6 @@ You can then use the following configuration to invoke this validator: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - /** - * @Assert\Callback({"Acme\Validator", "validate"}) - */ - class Author - { - } - .. code-block:: php-attributes // src/Entity/Author.php @@ -280,8 +247,8 @@ constructor of the Callback constraint:: .. warning:: - Using a ``Closure`` together with annotation configuration will disable the - annotation cache for that class/property/method because ``Closure`` cannot + Using a ``Closure`` together with attribute configuration will disable the + attribute cache for that class/property/method because ``Closure`` cannot be cached. For best performance, it's recommended to use a static callback method. Options diff --git a/reference/constraints/CardScheme.rst b/reference/constraints/CardScheme.rst index b01eed6460e..59f0d048f15 100644 --- a/reference/constraints/CardScheme.rst +++ b/reference/constraints/CardScheme.rst @@ -19,24 +19,6 @@ on an object that will contain a credit card number. .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Transaction.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Transaction - { - /** - * @Assert\CardScheme( - * schemes={"VISA"}, - * message="Your credit card number is invalid." - * ) - */ - protected $cardNumber; - } - .. code-block:: php-attributes // src/Entity/Transaction.php diff --git a/reference/constraints/Choice.rst b/reference/constraints/Choice.rst index 365d57e4960..a4150d82d55 100644 --- a/reference/constraints/Choice.rst +++ b/reference/constraints/Choice.rst @@ -23,30 +23,6 @@ If your valid choice list is simple, you can pass them in directly via the .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - const GENRES = ['fiction', 'non-fiction']; - - /** - * @Assert\Choice({"New York", "Berlin", "Tokyo"}) - */ - protected $city; - - /** - * You can also directly provide an array constant to the "choices" option in the annotation - * - * @Assert\Choice(choices=Author::GENRES, message="Choose a valid genre.") - */ - protected $genre; - } - .. code-block:: php-attributes // src/Entity/Author.php @@ -152,21 +128,6 @@ constraint. .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Choice(callback="getGenres") - */ - protected $genre; - } - .. code-block:: php-attributes // src/Entity/Author.php @@ -230,21 +191,6 @@ you can pass the class name and the method as an array. .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Choice(callback={"App\Entity\Genre", "getGenres"}) - */ - protected $genre; - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/reference/constraints/Cidr.rst b/reference/constraints/Cidr.rst index 0ad183a9e2b..31080ab1abb 100644 --- a/reference/constraints/Cidr.rst +++ b/reference/constraints/Cidr.rst @@ -17,21 +17,6 @@ Basic Usage .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/NetworkSettings.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class NetworkSettings - { - /** - * @Assert\Cidr - */ - protected $cidrNotation; - } - .. code-block:: php-attributes // src/Entity/NetworkSettings.php diff --git a/reference/constraints/Collection.rst b/reference/constraints/Collection.rst index 6830dcc0956..7ad50771226 100644 --- a/reference/constraints/Collection.rst +++ b/reference/constraints/Collection.rst @@ -51,36 +51,6 @@ following: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Collection( - * fields = { - * "personal_email" = @Assert\Email, - * "short_bio" = { - * @Assert\NotBlank, - * @Assert\Length( - * max = 100, - * maxMessage = "Your short bio is too long!" - * ) - * } - * }, - * allowMissingFields = true - * ) - */ - protected $profileData = [ - 'personal_email' => '...', - 'short_bio' => '...', - ]; - } - .. code-block:: php-attributes // src/Entity/Author.php @@ -214,7 +184,7 @@ you can do the following: .. configuration-block:: - .. code-block:: php-annotations + .. code-block:: php-attributes // src/Entity/Author.php namespace App\Entity; @@ -223,14 +193,17 @@ you can do the following: class Author { - /** - * @Assert\Collection( - * fields={ - * "personal_email" = @Assert\Required({@Assert\NotBlank, @Assert\Email}), - * "alternate_email" = @Assert\Optional(@Assert\Email) - * } - * ) - */ + #[Assert\Collection( + fields: [ + 'personal_email' => new Assert\Required([ + new Assert\NotBlank, + new Assert\Email, + ]), + 'alternate_email' => new Assert\Optional( + new Assert\Email + ), + ], + )] protected $profileData = ['personal_email' => 'email@example.com']; } diff --git a/reference/constraints/Compound.rst b/reference/constraints/Compound.rst index 2af5d157e94..695ae4f00ec 100644 --- a/reference/constraints/Compound.rst +++ b/reference/constraints/Compound.rst @@ -19,30 +19,6 @@ you can create your own named set or requirements to be reused consistently ever .. configuration-block:: - .. code-block:: php-annotations - - // src/Validator/Constraints/PasswordRequirements.php - namespace App\Validator\Constraints; - - use Symfony\Component\Validator\Constraints\Compound; - use Symfony\Component\Validator\Constraints as Assert; - - /** - * @Annotation - */ - class PasswordRequirements extends Compound - { - protected function getConstraints(array $options): array - { - return [ - new Assert\NotBlank(), - new Assert\Type('string'), - new Assert\Length(['min' => 12]), - new Assert\NotCompromisedPassword(), - ]; - } - } - .. code-block:: php-attributes // src/Validator/Constraints/PasswordRequirements.php @@ -65,29 +41,14 @@ you can create your own named set or requirements to be reused consistently ever } } -Add ``@Annotation`` or ``#[\Attribute]`` to the constraint class if you want to -use it as an annotation/attribute in other classes. If the constraint has +Add ``#[\Attribute]`` to the constraint class if you want to +use it as an attribute in other classes. If the constraint has configuration options, define them as public properties on the constraint class. You can now use it anywhere you need it: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/User.php - namespace App\Entity\User; - - use App\Validator\Constraints as Assert; - - class User - { - /** - * @Assert\PasswordRequirements() - */ - public $plainPassword; - } - .. code-block:: php-attributes // src/Entity/User.php diff --git a/reference/constraints/Count.rst b/reference/constraints/Count.rst index 59c75351906..71597687931 100644 --- a/reference/constraints/Count.rst +++ b/reference/constraints/Count.rst @@ -18,26 +18,6 @@ you might add the following: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Participant.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Participant - { - /** - * @Assert\Count( - * min = 1, - * max = 5, - * minMessage = "You must specify at least one email", - * maxMessage = "You cannot specify more than {{ limit }} emails" - * ) - */ - protected $emails = []; - } - .. code-block:: php-attributes // src/Entity/Participant.php diff --git a/reference/constraints/Country.rst b/reference/constraints/Country.rst index b3b65638646..5a47a7cae44 100644 --- a/reference/constraints/Country.rst +++ b/reference/constraints/Country.rst @@ -14,21 +14,6 @@ Basic Usage .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/User.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class User - { - /** - * @Assert\Country - */ - protected $country; - } - .. code-block:: php-attributes // src/Entity/User.php diff --git a/reference/constraints/CssColor.rst b/reference/constraints/CssColor.rst index 4d6a7cce7e2..383c112fa85 100644 --- a/reference/constraints/CssColor.rst +++ b/reference/constraints/CssColor.rst @@ -21,40 +21,6 @@ the named CSS colors: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Bulb.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Bulb - { - /** - * @Assert\CssColor - */ - protected $defaultColor; - - /** - * @Assert\CssColor( - * formats = Assert\CssColor::HEX_LONG, - * message = "The accent color must be a 6-character hexadecimal color." - * ) - */ - protected $accentColor; - - /** - * @Assert\CssColor( - * formats = { - * Assert\CssColor::BASIC_NAMED_COLORS, - * Assert\CssColor::EXTENDED_NAMED_COLORS - * }, - * message = "The color '{{ value }}' is not a valid CSS color name." - * ) - */ - protected $currentColor; - } - .. code-block:: php-attributes // src/Entity/Bulb.php diff --git a/reference/constraints/Currency.rst b/reference/constraints/Currency.rst index 32e806edca0..ccf1a2928bf 100644 --- a/reference/constraints/Currency.rst +++ b/reference/constraints/Currency.rst @@ -17,21 +17,6 @@ a valid currency, you could do the following: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Order.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Order - { - /** - * @Assert\Currency - */ - protected $currency; - } - .. code-block:: php-attributes // src/Entity/Order.php diff --git a/reference/constraints/Date.rst b/reference/constraints/Date.rst index 8bb0ddb20e1..aad3db2faef 100644 --- a/reference/constraints/Date.rst +++ b/reference/constraints/Date.rst @@ -15,22 +15,6 @@ Basic Usage .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Date - * @var string A "Y-m-d" formatted value - */ - protected $birthday; - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/reference/constraints/DateTime.rst b/reference/constraints/DateTime.rst index 66c7f83c69d..39ca4e3a5a1 100644 --- a/reference/constraints/DateTime.rst +++ b/reference/constraints/DateTime.rst @@ -15,22 +15,6 @@ Basic Usage .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\DateTime - * @var string A "Y-m-d H:i:s" formatted value - */ - protected $createdAt; - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/reference/constraints/DivisibleBy.rst b/reference/constraints/DivisibleBy.rst index 2c1fdb4fe87..19f69414dd5 100644 --- a/reference/constraints/DivisibleBy.rst +++ b/reference/constraints/DivisibleBy.rst @@ -25,28 +25,6 @@ The following constraints ensure that: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Item.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Item - { - /** - * @Assert\DivisibleBy(0.25) - */ - protected $weight; - - /** - * @Assert\DivisibleBy( - * value = 5 - * ) - */ - protected $quantity; - } - .. code-block:: php-attributes // src/Entity/Item.php diff --git a/reference/constraints/Email.rst b/reference/constraints/Email.rst index f997c4e9292..7046fe4a893 100644 --- a/reference/constraints/Email.rst +++ b/reference/constraints/Email.rst @@ -15,23 +15,6 @@ Basic Usage .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Email( - * message = "The email '{{ value }}' is not a valid email." - * ) - */ - protected $email; - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/reference/constraints/EqualTo.rst b/reference/constraints/EqualTo.rst index 06578c27c19..41e95947963 100644 --- a/reference/constraints/EqualTo.rst +++ b/reference/constraints/EqualTo.rst @@ -25,28 +25,6 @@ and that the ``age`` is ``20``, you could do the following: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Person.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Person - { - /** - * @Assert\EqualTo("Mary") - */ - protected $firstName; - - /** - * @Assert\EqualTo( - * value = 20 - * ) - */ - protected $age; - } - .. code-block:: php-attributes // src/Entity/Person.php diff --git a/reference/constraints/Expression.rst b/reference/constraints/Expression.rst index 1df2fe73653..1cfa8b5a058 100644 --- a/reference/constraints/Expression.rst +++ b/reference/constraints/Expression.rst @@ -55,24 +55,6 @@ One way to accomplish this is with the Expression constraint: .. configuration-block:: - .. code-block:: php-annotations - - // src/Model/BlogPost.php - namespace App\Model; - - use Symfony\Component\Validator\Constraints as Assert; - - /** - * @Assert\Expression( - * "this.getCategory() in ['php', 'symfony'] or !this.isTechnicalPost()", - * message="If this is a tech post, the category should be either php or symfony!" - * ) - */ - class BlogPost - { - // ... - } - .. code-block:: php-attributes // src/Model/BlogPost.php @@ -152,28 +134,6 @@ more about the expression language syntax, see .. configuration-block:: - .. code-block:: php-annotations - - // src/Model/BlogPost.php - namespace App\Model; - - use Symfony\Component\Validator\Constraints as Assert; - - class BlogPost - { - // ... - - /** - * @Assert\Expression( - * "this.getCategory() in ['php', 'symfony'] or value == false", - * message="If this is a tech post, the category should be either php or symfony!" - * ) - */ - private $isTechnicalPost; - - // ... - } - .. code-block:: php-attributes // src/Model/BlogPost.php @@ -306,26 +266,6 @@ type (numeric, boolean, strings, null, etc.) .. configuration-block:: - .. code-block:: php-annotations - - // src/Model/Analysis.php - namespace App\Model; - - use Symfony\Component\Validator\Constraints as Assert; - - class Analysis - { - /** - * @Assert\Expression( - * "value + error_margin < threshold", - * values = { "error_margin": 0.25, "threshold": 1.5 } - * ) - */ - private $metric; - - // ... - } - .. code-block:: php-attributes // src/Model/Analysis.php diff --git a/reference/constraints/ExpressionLanguageSyntax.rst b/reference/constraints/ExpressionLanguageSyntax.rst index 58309ed39d0..7fba9fb69fa 100644 --- a/reference/constraints/ExpressionLanguageSyntax.rst +++ b/reference/constraints/ExpressionLanguageSyntax.rst @@ -22,28 +22,6 @@ The following constraints ensure that: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Order.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Order - { - /** - * @Assert\ExpressionLanguageSyntax - */ - protected $promotion; - - /** - * @Assert\ExpressionLanguageSyntax( - * allowedVariables={"user", "shipping_centers"} - * ) - */ - protected $shippingOptions; - } - .. code-block:: php-attributes // src/Entity/Order.php diff --git a/reference/constraints/File.rst b/reference/constraints/File.rst index 1eaed6075d0..8f36f2d10f5 100644 --- a/reference/constraints/File.rst +++ b/reference/constraints/File.rst @@ -56,25 +56,6 @@ below a certain file size and a valid PDF, add the following: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\File( - * maxSize = "1024k", - * mimeTypes = {"application/pdf", "application/x-pdf"}, - * mimeTypesMessage = "Please upload a valid PDF" - * ) - */ - protected $bioFile; - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/reference/constraints/GreaterThan.rst b/reference/constraints/GreaterThan.rst index 22331edd957..3695486491c 100644 --- a/reference/constraints/GreaterThan.rst +++ b/reference/constraints/GreaterThan.rst @@ -22,28 +22,6 @@ The following constraints ensure that: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Person.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Person - { - /** - * @Assert\GreaterThan(5) - */ - protected $siblings; - - /** - * @Assert\GreaterThan( - * value = 18 - * ) - */ - protected $age; - } - .. code-block:: php-attributes // src/Entity/Person.php @@ -124,21 +102,6 @@ that a date must at least be the next day: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Order.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Order - { - /** - * @Assert\GreaterThan("today") - */ - protected $deliveryDate; - } - .. code-block:: php-attributes // src/Entity/Order.php @@ -196,21 +159,6 @@ dates. If you want to fix the timezone, append it to the date string: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Order.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Order - { - /** - * @Assert\GreaterThan("today UTC") - */ - protected $deliveryDate; - } - .. code-block:: php-attributes // src/Entity/Order.php @@ -269,21 +217,6 @@ current time: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Order.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Order - { - /** - * @Assert\GreaterThan("+5 hours") - */ - protected $deliveryDate; - } - .. code-block:: php-attributes // src/Entity/Order.php diff --git a/reference/constraints/GreaterThanOrEqual.rst b/reference/constraints/GreaterThanOrEqual.rst index 79578c5a5f7..0adb729eae7 100644 --- a/reference/constraints/GreaterThanOrEqual.rst +++ b/reference/constraints/GreaterThanOrEqual.rst @@ -21,28 +21,6 @@ The following constraints ensure that: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Person.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Person - { - /** - * @Assert\GreaterThanOrEqual(5) - */ - protected $siblings; - - /** - * @Assert\GreaterThanOrEqual( - * value = 18 - * ) - */ - protected $age; - } - .. code-block:: php-attributes // src/Entity/Person.php @@ -123,21 +101,6 @@ that a date must at least be the current day: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Order.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Order - { - /** - * @Assert\GreaterThanOrEqual("today") - */ - protected $deliveryDate; - } - .. code-block:: php-attributes // src/Entity/Order.php @@ -195,21 +158,6 @@ dates. If you want to fix the timezone, append it to the date string: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Order.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Order - { - /** - * @Assert\GreaterThanOrEqual("today UTC") - */ - protected $deliveryDate; - } - .. code-block:: php-attributes // src/Entity/Order.php @@ -268,21 +216,6 @@ current time: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Order.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Order - { - /** - * @Assert\GreaterThanOrEqual("+5 hours") - */ - protected $deliveryDate; - } - .. code-block:: php-attributes // src/Entity/Order.php diff --git a/reference/constraints/Hostname.rst b/reference/constraints/Hostname.rst index 502b3179bc7..eea851b144f 100644 --- a/reference/constraints/Hostname.rst +++ b/reference/constraints/Hostname.rst @@ -19,21 +19,6 @@ will contain a host name. .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/ServerSettings.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class ServerSettings - { - /** - * @Assert\Hostname(message="The server name must be a valid hostname.") - */ - protected $name; - } - .. code-block:: php-attributes // src/Entity/ServerSettings.php diff --git a/reference/constraints/Iban.rst b/reference/constraints/Iban.rst index 50ca887b6a9..d7f5b7c4140 100644 --- a/reference/constraints/Iban.rst +++ b/reference/constraints/Iban.rst @@ -20,23 +20,6 @@ will contain an International Bank Account Number. .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Transaction.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Transaction - { - /** - * @Assert\Iban( - * message="This is not a valid International Bank Account Number (IBAN)." - * ) - */ - protected $bankAccountNumber; - } - .. code-block:: php-attributes // src/Entity/Transaction.php diff --git a/reference/constraints/IdenticalTo.rst b/reference/constraints/IdenticalTo.rst index f5b2644e3a9..1b3c9a357e9 100644 --- a/reference/constraints/IdenticalTo.rst +++ b/reference/constraints/IdenticalTo.rst @@ -27,28 +27,6 @@ The following constraints ensure that: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Person.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Person - { - /** - * @Assert\IdenticalTo("Mary") - */ - protected $firstName; - - /** - * @Assert\IdenticalTo( - * value = 20 - * ) - */ - protected $age; - } - .. code-block:: php-attributes // src/Entity/Person.php diff --git a/reference/constraints/Image.rst b/reference/constraints/Image.rst index 5cb45c7e097..51f40ed8a5b 100644 --- a/reference/constraints/Image.rst +++ b/reference/constraints/Image.rst @@ -51,26 +51,6 @@ that it is between a certain size, add the following: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Image( - * minWidth = 200, - * maxWidth = 400, - * minHeight = 200, - * maxHeight = 400 - * ) - */ - protected $headshot; - } - .. code-block:: php-attributes // src/Entity/Author.php @@ -151,24 +131,6 @@ following code: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Image( - * allowLandscape = false, - * allowPortrait = false - * ) - */ - protected $headshot; - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/reference/constraints/Ip.rst b/reference/constraints/Ip.rst index d974f7ec79f..c3719800d1e 100644 --- a/reference/constraints/Ip.rst +++ b/reference/constraints/Ip.rst @@ -16,21 +16,6 @@ Basic Usage .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Ip - */ - protected $ipAddress; - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/reference/constraints/IsFalse.rst b/reference/constraints/IsFalse.rst index 16b57c0c398..05a1cd1c401 100644 --- a/reference/constraints/IsFalse.rst +++ b/reference/constraints/IsFalse.rst @@ -35,26 +35,6 @@ method returns **false**: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\IsFalse( - * message = "You've entered an invalid state." - * ) - */ - public function isStateInvalid() - { - // ... - } - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/reference/constraints/IsNull.rst b/reference/constraints/IsNull.rst index ac9bbeac114..107ac662870 100644 --- a/reference/constraints/IsNull.rst +++ b/reference/constraints/IsNull.rst @@ -21,21 +21,6 @@ of an ``Author`` class exactly equal to ``null``, you could do the following: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\IsNull - */ - protected $firstName; - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/reference/constraints/IsTrue.rst b/reference/constraints/IsTrue.rst index d48660036cc..f1700f599d1 100644 --- a/reference/constraints/IsTrue.rst +++ b/reference/constraints/IsTrue.rst @@ -37,26 +37,6 @@ Then you can validate this method with ``IsTrue`` as follows: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - protected $token; - - /** - * @Assert\IsTrue(message="The token is invalid.") - */ - public function isTokenValid() - { - return $this->token == $this->generateToken(); - } - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/reference/constraints/Isbn.rst b/reference/constraints/Isbn.rst index 9ea26d0d01b..0152abdde55 100644 --- a/reference/constraints/Isbn.rst +++ b/reference/constraints/Isbn.rst @@ -18,24 +18,6 @@ on an object that will contain an ISBN. .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Book.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Book - { - /** - * @Assert\Isbn( - * type = "isbn10", - * message = "This value is not valid." - * ) - */ - protected $isbn; - } - .. code-block:: php-attributes // src/Entity/Book.php diff --git a/reference/constraints/Isin.rst b/reference/constraints/Isin.rst index 309daff0e0e..8f06a003f0f 100644 --- a/reference/constraints/Isin.rst +++ b/reference/constraints/Isin.rst @@ -15,21 +15,6 @@ Basic Usage .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/UnitAccount.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class UnitAccount - { - /** - * @Assert\Isin - */ - protected $isin; - } - .. code-block:: php-attributes // src/Entity/UnitAccount.php diff --git a/reference/constraints/Issn.rst b/reference/constraints/Issn.rst index 18587bf0165..6e934dcdc2f 100644 --- a/reference/constraints/Issn.rst +++ b/reference/constraints/Issn.rst @@ -15,21 +15,6 @@ Basic Usage .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Journal.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Journal - { - /** - * @Assert\Issn - */ - protected $issn; - } - .. code-block:: php-attributes // src/Entity/Journal.php diff --git a/reference/constraints/Json.rst b/reference/constraints/Json.rst index c76c7cf3edc..1ab6ce46494 100644 --- a/reference/constraints/Json.rst +++ b/reference/constraints/Json.rst @@ -16,23 +16,6 @@ The ``Json`` constraint can be applied to a property or a "getter" method: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Book.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Book - { - /** - * @Assert\Json( - * message = "You've entered an invalid Json." - * ) - */ - private $chapters; - } - .. code-block:: php-attributes // src/Entity/Book.php diff --git a/reference/constraints/Language.rst b/reference/constraints/Language.rst index daec18d51fb..6b52d2ef6ae 100644 --- a/reference/constraints/Language.rst +++ b/reference/constraints/Language.rst @@ -15,21 +15,6 @@ Basic Usage .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/User.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class User - { - /** - * @Assert\Language - */ - protected $preferredLanguage; - } - .. code-block:: php-attributes // src/Entity/User.php diff --git a/reference/constraints/Length.rst b/reference/constraints/Length.rst index 140f804092e..d45a8c31d93 100644 --- a/reference/constraints/Length.rst +++ b/reference/constraints/Length.rst @@ -17,26 +17,6 @@ and ``50``, you might add the following: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Participant.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Participant - { - /** - * @Assert\Length( - * min = 2, - * max = 50, - * minMessage = "Your first name must be at least {{ limit }} characters long", - * maxMessage = "Your first name cannot be longer than {{ limit }} characters" - * ) - */ - protected $firstName; - } - .. code-block:: php-attributes // src/Entity/Participant.php diff --git a/reference/constraints/LessThan.rst b/reference/constraints/LessThan.rst index 22ebce5c094..913624e46d8 100644 --- a/reference/constraints/LessThan.rst +++ b/reference/constraints/LessThan.rst @@ -22,28 +22,6 @@ The following constraints ensure that: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Person.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Person - { - /** - * @Assert\LessThan(5) - */ - protected $siblings; - - /** - * @Assert\LessThan( - * value = 80 - * ) - */ - protected $age; - } - .. code-block:: php-attributes // src/Entity/Person.php @@ -124,21 +102,6 @@ that a date must be in the past like this: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Person.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Person - { - /** - * @Assert\LessThan("today") - */ - protected $dateOfBirth; - } - .. code-block:: php-attributes // src/Entity/Person.php @@ -196,21 +159,6 @@ dates. If you want to fix the timezone, append it to the date string: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Person.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Person - { - /** - * @Assert\LessThan("today UTC") - */ - protected $dateOfBirth; - } - .. code-block:: php-attributes // src/Entity/Person.php @@ -268,21 +216,6 @@ can check that a person must be at least 18 years old like this: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Person.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Person - { - /** - * @Assert\LessThan("-18 years") - */ - protected $dateOfBirth; - } - .. code-block:: php-attributes // src/Entity/Person.php diff --git a/reference/constraints/LessThanOrEqual.rst b/reference/constraints/LessThanOrEqual.rst index 05e2dedbfe5..91f5e50b6f4 100644 --- a/reference/constraints/LessThanOrEqual.rst +++ b/reference/constraints/LessThanOrEqual.rst @@ -21,28 +21,6 @@ The following constraints ensure that: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Person.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Person - { - /** - * @Assert\LessThanOrEqual(5) - */ - protected $siblings; - - /** - * @Assert\LessThanOrEqual( - * value = 80 - * ) - */ - protected $age; - } - .. code-block:: php-attributes // src/Entity/Person.php @@ -123,21 +101,6 @@ that a date must be today or in the past like this: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Person.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Person - { - /** - * @Assert\LessThanOrEqual("today") - */ - protected $dateOfBirth; - } - .. code-block:: php-attributes // src/Entity/Person.php @@ -195,21 +158,6 @@ dates. If you want to fix the timezone, append it to the date string: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Person.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Person - { - /** - * @Assert\LessThanOrEqual("today UTC") - */ - protected $dateOfBirth; - } - .. code-block:: php-attributes // src/Entity/Person.php @@ -267,21 +215,6 @@ can check that a person must be at least 18 years old like this: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Person.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Person - { - /** - * @Assert\LessThanOrEqual("-18 years") - */ - protected $dateOfBirth; - } - .. code-block:: php-attributes // src/Entity/Person.php diff --git a/reference/constraints/Locale.rst b/reference/constraints/Locale.rst index 7df56e456cf..f1c5b91627d 100644 --- a/reference/constraints/Locale.rst +++ b/reference/constraints/Locale.rst @@ -23,23 +23,6 @@ Basic Usage .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/User.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class User - { - /** - * @Assert\Locale( - * canonicalize = true - * ) - */ - protected $locale; - } - .. code-block:: php-attributes // src/Entity/User.php diff --git a/reference/constraints/Luhn.rst b/reference/constraints/Luhn.rst index cfc6fc54c4c..f89064030a6 100644 --- a/reference/constraints/Luhn.rst +++ b/reference/constraints/Luhn.rst @@ -19,21 +19,6 @@ will contain a credit card number. .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Transaction.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Transaction - { - /** - * @Assert\Luhn(message="Please check your credit card number.") - */ - protected $cardNumber; - } - .. code-block:: php-attributes // src/Entity/Transaction.php diff --git a/reference/constraints/Negative.rst b/reference/constraints/Negative.rst index c77d0586cbf..388a13fb222 100644 --- a/reference/constraints/Negative.rst +++ b/reference/constraints/Negative.rst @@ -19,21 +19,6 @@ The following constraint ensures that the ``withdraw`` of a bank account .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/TransferItem.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class TransferItem - { - /** - * @Assert\Negative - */ - protected $withdraw; - } - .. code-block:: php-attributes // src/Entity/TransferItem.php diff --git a/reference/constraints/NegativeOrZero.rst b/reference/constraints/NegativeOrZero.rst index 0aead7184e3..be6f3bc7566 100644 --- a/reference/constraints/NegativeOrZero.rst +++ b/reference/constraints/NegativeOrZero.rst @@ -18,21 +18,6 @@ is a negative number or equal to zero: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/TransferItem.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class UnderGroundGarage - { - /** - * @Assert\NegativeOrZero - */ - protected $level; - } - .. code-block:: php-attributes // src/Entity/TransferItem.php diff --git a/reference/constraints/NotBlank.rst b/reference/constraints/NotBlank.rst index b273d195eaa..6cf4770f21f 100644 --- a/reference/constraints/NotBlank.rst +++ b/reference/constraints/NotBlank.rst @@ -20,21 +20,6 @@ class were not blank, you could do the following: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\NotBlank - */ - protected $firstName; - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/reference/constraints/NotCompromisedPassword.rst b/reference/constraints/NotCompromisedPassword.rst index 74729853128..0e4bf194e68 100644 --- a/reference/constraints/NotCompromisedPassword.rst +++ b/reference/constraints/NotCompromisedPassword.rst @@ -18,21 +18,6 @@ The following constraint ensures that the ``rawPassword`` property of the .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/User.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class User - { - /** - * @Assert\NotCompromisedPassword - */ - protected $rawPassword; - } - .. code-block:: php-attributes // src/Entity/User.php diff --git a/reference/constraints/NotEqualTo.rst b/reference/constraints/NotEqualTo.rst index 993402f0964..e957971ade0 100644 --- a/reference/constraints/NotEqualTo.rst +++ b/reference/constraints/NotEqualTo.rst @@ -26,28 +26,6 @@ the following: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Person.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Person - { - /** - * @Assert\NotEqualTo("Mary") - */ - protected $firstName; - - /** - * @Assert\NotEqualTo( - * value = 15 - * ) - */ - protected $age; - } - .. code-block:: php-attributes // src/Entity/Person.php diff --git a/reference/constraints/NotIdenticalTo.rst b/reference/constraints/NotIdenticalTo.rst index 381aa5de2b5..c95a791a7bb 100644 --- a/reference/constraints/NotIdenticalTo.rst +++ b/reference/constraints/NotIdenticalTo.rst @@ -27,28 +27,6 @@ The following constraints ensure that: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Person.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Person - { - /** - * @Assert\NotIdenticalTo("Mary") - */ - protected $firstName; - - /** - * @Assert\NotIdenticalTo( - * value = 15 - * ) - */ - protected $age; - } - .. code-block:: php-attributes // src/Entity/Person.php diff --git a/reference/constraints/NotNull.rst b/reference/constraints/NotNull.rst index 44a774757c9..ff0f8eaf27a 100644 --- a/reference/constraints/NotNull.rst +++ b/reference/constraints/NotNull.rst @@ -19,21 +19,6 @@ class were not strictly equal to ``null``, you would: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\NotNull - */ - protected $firstName; - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/reference/constraints/Positive.rst b/reference/constraints/Positive.rst index b918c21695a..523a03be65c 100644 --- a/reference/constraints/Positive.rst +++ b/reference/constraints/Positive.rst @@ -19,21 +19,6 @@ positive number (greater than zero): .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Employee.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Employee - { - /** - * @Assert\Positive - */ - protected $income; - } - .. code-block:: php-attributes // src/Entity/Employee.php diff --git a/reference/constraints/PositiveOrZero.rst b/reference/constraints/PositiveOrZero.rst index 2d39d0d6d19..7596bdf3e50 100644 --- a/reference/constraints/PositiveOrZero.rst +++ b/reference/constraints/PositiveOrZero.rst @@ -18,21 +18,6 @@ is positive or zero: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Person.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Person - { - /** - * @Assert\PositiveOrZero - */ - protected $siblings; - } - .. code-block:: php-attributes // src/Entity/Person.php diff --git a/reference/constraints/Range.rst b/reference/constraints/Range.rst index 9dbbd4cdae2..4846c01fd2c 100644 --- a/reference/constraints/Range.rst +++ b/reference/constraints/Range.rst @@ -17,25 +17,6 @@ you might add the following: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Participant.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Participant - { - /** - * @Assert\Range( - * min = 120, - * max = 180, - * notInRangeMessage = "You must be between {{ min }}cm and {{ max }}cm tall to enter", - * ) - */ - protected $height; - } - .. code-block:: php-attributes // src/Entity/Participant.php @@ -113,24 +94,6 @@ date must lie within the current year like this: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Event.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Event - { - /** - * @Assert\Range( - * min = "first day of January", - * max = "first day of January next year" - * ) - */ - protected $startDate; - } - .. code-block:: php-attributes // src/Entity/Event.php @@ -199,24 +162,6 @@ dates. If you want to fix the timezone, append it to the date string: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Event.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Event - { - /** - * @Assert\Range( - * min = "first day of January UTC", - * max = "first day of January next year UTC" - * ) - */ - protected $startDate; - } - .. code-block:: php-attributes // src/Entity/Event.php @@ -285,24 +230,6 @@ can check that a delivery date starts within the next five hours like this: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Order.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Order - { - /** - * @Assert\Range( - * min = "now", - * max = "+5 hours" - * ) - */ - protected $deliveryDate; - } - .. code-block:: php-attributes // src/Entity/Order.php diff --git a/reference/constraints/Regex.rst b/reference/constraints/Regex.rst index 0edcf44aae0..6f94c5c151e 100644 --- a/reference/constraints/Regex.rst +++ b/reference/constraints/Regex.rst @@ -19,21 +19,6 @@ more word characters at the beginning of your string: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Regex("/^\w+/") - */ - protected $description; - } - .. code-block:: php-attributes // src/Entity/Author.php @@ -97,25 +82,6 @@ it a custom message: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Regex( - * pattern="/\d/", - * match=false, - * message="Your name cannot contain a number" - * ) - */ - protected $firstName; - } - .. code-block:: php-attributes // src/Entity/Author.php @@ -208,24 +174,6 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Regex( - * pattern = "/^[a-z]+$/i", - * htmlPattern = "[a-zA-Z]+" - * ) - */ - protected $name; - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/reference/constraints/Sequentially.rst b/reference/constraints/Sequentially.rst index 49eb07c5aa0..09fed581d25 100644 --- a/reference/constraints/Sequentially.rst +++ b/reference/constraints/Sequentially.rst @@ -36,30 +36,6 @@ You can validate each of these constraints sequentially to solve these issues: .. configuration-block:: - .. code-block:: php-annotations - - // src/Localization/Place.php - namespace App\Localization; - - use App\Validator\Constraints as AcmeAssert; - use Symfony\Component\Validator\Constraints as Assert; - - class Place - { - /** - * @var string - * - * @Assert\Sequentially({ - * @Assert\NotNull(), - * @Assert\Type("string"), - * @Assert\Length(min=10), - * @Assert\Regex(Place::ADDRESS_REGEX), - * @AcmeAssert\Geolocalizable(), - * }) - */ - public $address; - } - .. code-block:: php-attributes // src/Localization/Place.php diff --git a/reference/constraints/Time.rst b/reference/constraints/Time.rst index 91904fb5c9d..03f664c3556 100644 --- a/reference/constraints/Time.rst +++ b/reference/constraints/Time.rst @@ -18,22 +18,6 @@ of the day when the event starts: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Event.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Event - { - /** - * @Assert\Time - * @var string A "H:i:s" formatted value - */ - protected $startsAt; - } - .. code-block:: php-attributes // src/Entity/Event.php diff --git a/reference/constraints/Timezone.rst b/reference/constraints/Timezone.rst index 3f6947e5e83..e410c5dee90 100644 --- a/reference/constraints/Timezone.rst +++ b/reference/constraints/Timezone.rst @@ -17,21 +17,6 @@ string which contains any of the `PHP timezone identifiers`_ (e.g. ``America/New .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/UserSettings.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class UserSettings - { - /** - * @Assert\Timezone - */ - protected $timezone; - } - .. code-block:: php-attributes // src/Entity/UserSettings.php diff --git a/reference/constraints/Traverse.rst b/reference/constraints/Traverse.rst index 96c4bd9f211..b39431e2304 100644 --- a/reference/constraints/Traverse.rst +++ b/reference/constraints/Traverse.rst @@ -147,21 +147,6 @@ disable validating: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/BookCollection.php - - // ... same as above - - /** - * ... - * @Assert\Traverse(false) - */ - class BookCollection implements \IteratorAggregate - { - // ... - } - .. code-block:: php-attributes // src/Entity/BookCollection.php diff --git a/reference/constraints/Type.rst b/reference/constraints/Type.rst index 2f5c14a2c88..ee460d1718f 100644 --- a/reference/constraints/Type.rst +++ b/reference/constraints/Type.rst @@ -22,39 +22,6 @@ This will check if ``emailAddress`` is an instance of ``Symfony\Component\Mime\A .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Type("Symfony\Component\Mime\Address") - */ - protected $emailAddress; - - /** - * @Assert\Type("string") - */ - protected $firstName; - - /** - * @Assert\Type( - * type="integer", - * message="The value {{ value }} is not a valid {{ type }}." - * ) - */ - protected $age; - - /** - * @Assert\Type(type={"alpha", "digit"}) - */ - protected $accessCode; - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/reference/constraints/Ulid.rst b/reference/constraints/Ulid.rst index 6c2b8cdf48d..1ecdbf6659f 100644 --- a/reference/constraints/Ulid.rst +++ b/reference/constraints/Ulid.rst @@ -14,21 +14,6 @@ Basic Usage .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/File.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class File - { - /** - * @Assert\Ulid - */ - protected $identifier; - } - .. code-block:: php-attributes // src/Entity/File.php diff --git a/reference/constraints/Unique.rst b/reference/constraints/Unique.rst index 7a3e36c5aba..37207ea9f81 100644 --- a/reference/constraints/Unique.rst +++ b/reference/constraints/Unique.rst @@ -33,21 +33,6 @@ strings: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Person.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Person - { - /** - * @Assert\Unique - */ - protected $contactEmails; - } - .. code-block:: php-attributes // src/Entity/Person.php diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst index 82b49480b95..47b90a05c37 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -14,21 +14,6 @@ Basic Usage .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Url - */ - protected $bioUrl; - } - .. code-block:: php-attributes // src/Entity/Author.php @@ -110,23 +95,6 @@ Parameter Description .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Url( - * message = "The url '{{ value }}' is not a valid url", - * ) - */ - protected $bioUrl; - } - .. code-block:: php-attributes // src/Entity/Author.php @@ -201,23 +169,6 @@ the ``ftp://`` type URLs to be valid, redefine the ``protocols`` array, listing .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Url( - * protocols = {"http", "https", "ftp"} - * ) - */ - protected $bioUrl; - } - .. code-block:: php-attributes // src/Entity/Author.php @@ -291,23 +242,6 @@ also relative URLs that contain no protocol (e.g. ``//example.com``). .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Url( - * relativeProtocol = true - * ) - */ - protected $bioUrl; - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/reference/constraints/UserPassword.rst b/reference/constraints/UserPassword.rst index c1632c3f7c7..ad2d0a3eda8 100644 --- a/reference/constraints/UserPassword.rst +++ b/reference/constraints/UserPassword.rst @@ -31,23 +31,6 @@ the user's current password: .. configuration-block:: - .. code-block:: php-annotations - - // src/Form/Model/ChangePassword.php - namespace App\Form\Model; - - use Symfony\Component\Security\Core\Validator\Constraints as SecurityAssert; - - class ChangePassword - { - /** - * @SecurityAssert\UserPassword( - * message = "Wrong value for your current password" - * ) - */ - protected $oldPassword; - } - .. code-block:: php-attributes // src/Form/Model/ChangePassword.php diff --git a/reference/constraints/Uuid.rst b/reference/constraints/Uuid.rst index 7b3f355ed59..fff97d10171 100644 --- a/reference/constraints/Uuid.rst +++ b/reference/constraints/Uuid.rst @@ -17,21 +17,6 @@ Basic Usage .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/File.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class File - { - /** - * @Assert\Uuid - */ - protected $identifier; - } - .. code-block:: php-attributes // src/Entity/File.php diff --git a/reference/constraints/Valid.rst b/reference/constraints/Valid.rst index ba4e789091c..3c0e1937708 100644 --- a/reference/constraints/Valid.rst +++ b/reference/constraints/Valid.rst @@ -42,48 +42,6 @@ stores an ``Address`` instance in the ``$address`` property:: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Address.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Address - { - /** - * @Assert\NotBlank - */ - protected $street; - - /** - * @Assert\NotBlank - * @Assert\Length(max=5) - */ - protected $zipCode; - } - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\NotBlank - * @Assert\Length(min=4) - */ - protected $firstName; - - /** - * @Assert\NotBlank - */ - protected $lastName; - - protected $address; - } - .. code-block:: php-attributes // src/Entity/Address.php @@ -212,21 +170,6 @@ an invalid address. To prevent that, add the ``Valid`` constraint to the .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Valid - */ - protected $address; - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/validation.rst b/validation.rst index 7eb6cfd47b8..5b9fbcb9ce8 100644 --- a/validation.rst +++ b/validation.rst @@ -24,13 +24,6 @@ install the validator before using it: .. code-block:: terminal $ composer require symfony/validator - -If your project still uses annotations to define the validation constraints (as -shown later in this article) you also need to install ``doctrine/annotations``: - -.. code-block:: terminal - - $ composer require doctrine/annotations .. note:: @@ -61,7 +54,7 @@ application. The goal of validation is to tell you if the data of an object is valid. For this to work, you'll configure a list of rules (called :ref:`constraints `) that the object must follow in order to be valid. These rules are usually defined using PHP code or -annotations but they can also be defined as ``.yaml`` or ``.xml`` files inside +attributes but they can also be defined as ``.yaml`` or ``.xml`` files inside the ``config/validator/`` directory: For example, to indicate that the ``$name`` property must not be empty, add the @@ -69,22 +62,6 @@ following: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - // ... - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\NotBlank - */ - private $name; - } - .. code-block:: php-attributes // src/Entity/Author.php @@ -299,27 +276,6 @@ literature genre mostly associated with the author, which can be set to either .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - // ... - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Choice( - * choices = {"fiction", "non-fiction"}, - * message = "Choose a valid genre." - * ) - */ - private $genre; - - // ... - } - .. code-block:: php-attributes // src/Entity/Author.php @@ -407,24 +363,6 @@ options can be specified in this way. .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - // ... - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\Choice({"fiction", "non-fiction"}) - */ - private $genre; - - // ... - } - .. code-block:: php-attributes // src/Entity/Author.php @@ -547,22 +485,6 @@ class to have at least 3 characters. .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - - // ... - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\NotBlank - * @Assert\Length(min=3) - */ - private $firstName; - } - .. code-block:: php-attributes // src/Entity/Author.php @@ -654,25 +576,6 @@ this method must return ``true``: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - // ... - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\IsTrue(message="The password cannot match your first name") - */ - public function isPasswordSafe() - { - // ... return true or false - } - } - .. code-block:: php-attributes // src/Entity/Author.php diff --git a/validation/custom_constraint.rst b/validation/custom_constraint.rst index 0bec5c88c8b..3e2ca6dd2b9 100644 --- a/validation/custom_constraint.rst +++ b/validation/custom_constraint.rst @@ -127,27 +127,6 @@ You can use custom validators like the ones provided by Symfony itself: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/AcmeEntity.php - namespace App\Entity; - - use App\Validator as AcmeAssert; - use Symfony\Component\Validator\Constraints as Assert; - - class AcmeEntity - { - // ... - - /** - * @Assert\NotBlank - * @AcmeAssert\ContainsAlphanumeric(mode="loose") - */ - protected $name; - - // ... - } - .. code-block:: php-attributes // src/Entity/AcmeEntity.php @@ -275,7 +254,7 @@ not to the property: namespace App\Entity; use App\Validator as AcmeAssert; - + /** * @AcmeAssert\ProtocolClass */ diff --git a/validation/groups.rst b/validation/groups.rst index 60aa7efb2f2..8389d5fe238 100644 --- a/validation/groups.rst +++ b/validation/groups.rst @@ -15,33 +15,6 @@ user registers and when a user updates their contact information later: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/User.php - namespace App\Entity; - - use Symfony\Component\Security\Core\User\UserInterface; - use Symfony\Component\Validator\Constraints as Assert; - - class User implements UserInterface - { - /** - * @Assert\Email(groups={"registration"}) - */ - private $email; - - /** - * @Assert\NotBlank(groups={"registration"}) - * @Assert\Length(min=7, groups={"registration"}) - */ - private $password; - - /** - * @Assert\Length(min=2) - */ - private $city; - } - .. code-block:: php-attributes // src/Entity/User.php diff --git a/validation/sequence_provider.rst b/validation/sequence_provider.rst index fb196a3b6e9..1ebd33affcc 100644 --- a/validation/sequence_provider.rst +++ b/validation/sequence_provider.rst @@ -15,38 +15,6 @@ username and the password are different only if all other validation passes .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/User.php - namespace App\Entity; - - use Symfony\Component\Security\Core\User\UserInterface; - use Symfony\Component\Validator\Constraints as Assert; - - /** - * @Assert\GroupSequence({"User", "Strict"}) - */ - class User implements UserInterface - { - /** - * @Assert\NotBlank - */ - private $username; - - /** - * @Assert\NotBlank - */ - private $password; - - /** - * @Assert\IsTrue(message="The password cannot match your username", groups={"Strict"}) - */ - public function isPasswordSafe() - { - return ($this->username !== $this->password); - } - } - .. code-block:: php-attributes // src/Entity/User.php @@ -206,31 +174,6 @@ entity and a new constraint group called ``Premium``: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/User.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class User - { - /** - * @Assert\NotBlank - */ - private $name; - - /** - * @Assert\CardScheme( - * schemes={"VISA"}, - * groups={"Premium"}, - * ) - */ - private $creditCard; - - // ... - } - .. code-block:: php-attributes // src/Entity/User.php @@ -352,21 +295,6 @@ provides a sequence of groups to be validated: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/User.php - namespace App\Entity; - - // ... - - /** - * @Assert\GroupSequenceProvider - */ - class User implements GroupSequenceProviderInterface - { - // ... - } - .. code-block:: php-attributes // src/Entity/User.php diff --git a/validation/severity.rst b/validation/severity.rst index 7df7746c7f2..3cb58ca1e7f 100644 --- a/validation/severity.rst +++ b/validation/severity.rst @@ -25,31 +25,6 @@ Use the ``payload`` option to configure the error level for each constraint: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/User.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class User - { - /** - * @Assert\NotBlank(payload={"severity"="error"}) - */ - protected $username; - - /** - * @Assert\NotBlank(payload={"severity"="error"}) - */ - protected $password; - - /** - * @Assert\Iban(payload={"severity"="warning"}) - */ - protected $bankAccountNumber; - } - .. code-block:: php-attributes // src/Entity/User.php diff --git a/validation/translations.rst b/validation/translations.rst index 10ce5b11275..ff8340466d6 100644 --- a/validation/translations.rst +++ b/validation/translations.rst @@ -32,21 +32,6 @@ property is not empty, add the following: .. configuration-block:: - .. code-block:: php-annotations - - // src/Entity/Author.php - namespace App\Entity; - - use Symfony\Component\Validator\Constraints as Assert; - - class Author - { - /** - * @Assert\NotBlank(message="author.name.not_blank") - */ - public $name; - } - .. code-block:: php-attributes // src/Entity/Author.php