diff --git a/reference/constraints/All.rst b/reference/constraints/All.rst index cef70cc3690..0a95103d62e 100644 --- a/reference/constraints/All.rst +++ b/reference/constraints/All.rst @@ -39,7 +39,7 @@ entry in that array: * @Assert\Length(min=5) * }) */ - protected $favoriteColors = []; + protected $favoriteColors = []; } .. code-block:: yaml diff --git a/reference/constraints/Bic.rst b/reference/constraints/Bic.rst index 41c43e82359..7995431e7d8 100644 --- a/reference/constraints/Bic.rst +++ b/reference/constraints/Bic.rst @@ -73,8 +73,6 @@ will contain a Business Identifier Code (BIC). class Transaction { - protected $businessIdentifierCode; - public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('businessIdentifierCode', new Assert\Bic()); diff --git a/reference/constraints/Callback.rst b/reference/constraints/Callback.rst index 2905733cc79..95ab8a6a2ac 100644 --- a/reference/constraints/Callback.rst +++ b/reference/constraints/Callback.rst @@ -87,6 +87,11 @@ Configuration { $metadata->addConstraint(new Assert\Callback('validate')); } + + public function validate(ExecutionContextInterface $context, $payload) + { + // ... + } } The Callback Method diff --git a/reference/constraints/CardScheme.rst b/reference/constraints/CardScheme.rst index 52e2b72569e..1a68b413865 100644 --- a/reference/constraints/CardScheme.rst +++ b/reference/constraints/CardScheme.rst @@ -84,8 +84,6 @@ on an object that will contain a credit card number. class Transaction { - protected $cardNumber; - public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('cardNumber', new Assert\CardScheme([ diff --git a/reference/constraints/Choice.rst b/reference/constraints/Choice.rst index 302faca7255..231f2acba8f 100644 --- a/reference/constraints/Choice.rst +++ b/reference/constraints/Choice.rst @@ -112,8 +112,6 @@ If your valid choice list is simple, you can pass them in directly via the class Author { - protected $genre; - public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint( diff --git a/reference/constraints/Collection.rst b/reference/constraints/Collection.rst index 7e23a4cf8ed..94db7909dea 100644 --- a/reference/constraints/Collection.rst +++ b/reference/constraints/Collection.rst @@ -141,8 +141,6 @@ following: class Author { - private $options = []; - public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('profileData', new Assert\Collection([ @@ -208,7 +206,7 @@ you can do the following: * } * ) */ - protected $profileData = ['personal_email']; + protected $profileData = ['personal_email']; } .. code-block:: yaml @@ -272,9 +270,10 @@ you can do the following: { $metadata->addPropertyConstraint('profileData', new Assert\Collection([ 'fields' => [ - 'personal_email' => new Assert\Required( - [new Assert\NotBlank(), new Assert\Email()] - ), + 'personal_email' => new Assert\Required([ + new Assert\NotBlank(), + new Assert\Email(), + ]), 'alternate_email' => new Assert\Optional(new Assert\Email()), ], ])); diff --git a/reference/constraints/Count.rst b/reference/constraints/Count.rst index b37797dafc6..6308aeba33a 100644 --- a/reference/constraints/Count.rst +++ b/reference/constraints/Count.rst @@ -45,7 +45,7 @@ you might add the following: * maxMessage = "You cannot specify more than {{ limit }} emails" * ) */ - protected $emails = []; + protected $emails = []; } .. code-block:: yaml @@ -93,8 +93,8 @@ you might add the following: public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('emails', new Assert\Count([ - 'min' => 1, - 'max' => 5, + 'min' => 1, + 'max' => 5, 'minMessage' => 'You must specify at least one email', 'maxMessage' => 'You cannot specify more than {{ limit }} emails', ])); diff --git a/reference/constraints/Country.rst b/reference/constraints/Country.rst index 2ef348f4b12..7c52723953a 100644 --- a/reference/constraints/Country.rst +++ b/reference/constraints/Country.rst @@ -32,7 +32,7 @@ Basic Usage /** * @Assert\Country */ - protected $country; + protected $country; } .. code-block:: yaml diff --git a/reference/constraints/Date.rst b/reference/constraints/Date.rst index 46cad1e1a73..b9816764cea 100644 --- a/reference/constraints/Date.rst +++ b/reference/constraints/Date.rst @@ -34,7 +34,7 @@ Basic Usage /** * @Assert\Date */ - protected $birthday; + protected $birthday; } .. code-block:: yaml diff --git a/reference/constraints/DateTime.rst b/reference/constraints/DateTime.rst index b670bb71629..c81c04f8626 100644 --- a/reference/constraints/DateTime.rst +++ b/reference/constraints/DateTime.rst @@ -35,7 +35,7 @@ Basic Usage /** * @Assert\DateTime */ - protected $createdAt; + protected $createdAt; } .. code-block:: yaml diff --git a/reference/constraints/Email.rst b/reference/constraints/Email.rst index c07cb4845d1..e196150bb52 100644 --- a/reference/constraints/Email.rst +++ b/reference/constraints/Email.rst @@ -39,7 +39,7 @@ Basic Usage * checkMX = true * ) */ - protected $email; + protected $email; } .. code-block:: yaml diff --git a/reference/constraints/Image.rst b/reference/constraints/Image.rst index b907ca56d50..4f5529186dd 100644 --- a/reference/constraints/Image.rst +++ b/reference/constraints/Image.rst @@ -211,13 +211,11 @@ following code: class Author { - // ... - public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('headshot', new Assert\Image([ - 'allowLandscape' => false, - 'allowPortrait' => false, + 'allowLandscape' => false, + 'allowPortrait' => false, ])); } } diff --git a/reference/constraints/Ip.rst b/reference/constraints/Ip.rst index 7adfce8c2ff..c16a94d6df3 100644 --- a/reference/constraints/Ip.rst +++ b/reference/constraints/Ip.rst @@ -35,7 +35,7 @@ Basic Usage /** * @Assert\Ip */ - protected $ipAddress; + protected $ipAddress; } .. code-block:: yaml diff --git a/reference/constraints/IsFalse.rst b/reference/constraints/IsFalse.rst index 4fb67e1c63d..10148287e9d 100644 --- a/reference/constraints/IsFalse.rst +++ b/reference/constraints/IsFalse.rst @@ -55,10 +55,10 @@ method returns **false**: * message = "You've entered an invalid state." * ) */ - public function isStateInvalid() - { + public function isStateInvalid() + { // ... - } + } } .. code-block:: yaml @@ -99,10 +99,17 @@ method returns **false**: { public static function loadValidatorMetadata(ClassMetadata $metadata) { - $metadata->addGetterConstraint('stateInvalid', new Assert\IsFalse()); + $metadata->addGetterConstraint('stateInvalid', new Assert\IsFalse([ + 'message' => 'You've entered an invalid state.', + ])); } } + public function isStateInvalid() + { + // ... + } + Options ------- diff --git a/reference/constraints/IsTrue.rst b/reference/constraints/IsTrue.rst index ca5d0c7d534..6ea7f30037d 100644 --- a/reference/constraints/IsTrue.rst +++ b/reference/constraints/IsTrue.rst @@ -56,7 +56,7 @@ Then you can constrain this method with ``IsTrue``. protected $token; /** - * @Assert\IsTrue(message="The token is invalid") + * @Assert\IsTrue(message="The token is invalid.") */ public function isTokenValid() { @@ -100,8 +100,6 @@ Then you can constrain this method with ``IsTrue``. class Author { - protected $token; - public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addGetterConstraint('tokenValid', new IsTrue([ diff --git a/reference/constraints/Isbn.rst b/reference/constraints/Isbn.rst index b905d92cf06..4c543496084 100644 --- a/reference/constraints/Isbn.rst +++ b/reference/constraints/Isbn.rst @@ -84,12 +84,10 @@ on an object that will contain an ISBN. class Book { - protected $isbn; - public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('isbn', new Assert\Isbn([ - 'type' => 'isbn10', + 'type' => 'isbn10', 'message' => 'This value is not valid.', ])); } diff --git a/reference/constraints/Issn.rst b/reference/constraints/Issn.rst index 372fbc4b0f8..f409a17b94e 100644 --- a/reference/constraints/Issn.rst +++ b/reference/constraints/Issn.rst @@ -35,7 +35,7 @@ Basic Usage /** * @Assert\Issn */ - protected $issn; + protected $issn; } .. code-block:: yaml @@ -87,7 +87,7 @@ Options message ~~~~~~~ -**type**: ``String`` default: ``This value is not a valid ISSN.`` +**type**: ``string`` default: ``This value is not a valid ISSN.`` The message shown if the given value is not a valid ISSN. diff --git a/reference/constraints/Language.rst b/reference/constraints/Language.rst index fa83769328f..29eace137db 100644 --- a/reference/constraints/Language.rst +++ b/reference/constraints/Language.rst @@ -33,7 +33,7 @@ Basic Usage /** * @Assert\Language */ - protected $preferredLanguage; + protected $preferredLanguage; } .. code-block:: yaml diff --git a/reference/constraints/Length.rst b/reference/constraints/Length.rst index 39d91eb560a..c2f2b7ab030 100644 --- a/reference/constraints/Length.rst +++ b/reference/constraints/Length.rst @@ -52,7 +52,7 @@ and "50", you might add the following: * maxMessage = "Your first name cannot be longer than {{ limit }} characters" * ) */ - protected $firstName; + protected $firstName; } .. code-block:: yaml @@ -104,8 +104,8 @@ and "50", you might add the following: public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('firstName', new Assert\Length([ - 'min' => 2, - 'max' => 50, + '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', ])); diff --git a/reference/constraints/Locale.rst b/reference/constraints/Locale.rst index eb8b1bd0651..932bae1b5a3 100644 --- a/reference/constraints/Locale.rst +++ b/reference/constraints/Locale.rst @@ -37,7 +37,7 @@ Basic Usage /** * @Assert\Locale */ - protected $locale; + protected $locale; } .. code-block:: yaml diff --git a/reference/constraints/Range.rst b/reference/constraints/Range.rst index f69ec3231ba..cfb4e166d55 100644 --- a/reference/constraints/Range.rst +++ b/reference/constraints/Range.rst @@ -92,8 +92,8 @@ you might add the following: public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('height', new Assert\Range([ - 'min' => 120, - 'max' => 180, + 'min' => 120, + 'max' => 180, 'minMessage' => 'You must be at least {{ limit }}cm tall to enter', 'maxMessage' => 'You cannot be taller than {{ limit }}cm to enter', ])); diff --git a/reference/constraints/Regex.rst b/reference/constraints/Regex.rst index e1567d7baff..830684cd030 100644 --- a/reference/constraints/Regex.rst +++ b/reference/constraints/Regex.rst @@ -156,7 +156,7 @@ it a custom message: { $metadata->addPropertyConstraint('firstName', new Assert\Regex([ 'pattern' => '/\d/', - 'match' => false, + 'match' => false, 'message' => 'Your name cannot contain a number', ])); } @@ -257,7 +257,7 @@ need to specify the HTML5 compatible pattern in the ``htmlPattern`` option: public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('name', new Assert\Regex([ - 'pattern' => '/^[a-z]+$/i', + 'pattern' => '/^[a-z]+$/i', 'htmlPattern' => '^[a-zA-Z]+$', ])); } diff --git a/reference/constraints/Time.rst b/reference/constraints/Time.rst index 2051f1e4d02..7a57cc1b507 100644 --- a/reference/constraints/Time.rst +++ b/reference/constraints/Time.rst @@ -37,7 +37,7 @@ of the day when the event starts: /** * @Assert\Time */ - protected $startsAt; + protected $startsAt; } .. code-block:: yaml diff --git a/reference/constraints/Type.rst b/reference/constraints/Type.rst index a9e26e2f531..08a8f5e7471 100644 --- a/reference/constraints/Type.rst +++ b/reference/constraints/Type.rst @@ -100,7 +100,7 @@ This will check if ``firstName`` is of type ``string`` and that ``age`` is an $metadata->addPropertyConstraint('firstName', new Assert\Type('string')); $metadata->addPropertyConstraint('age', new Assert\Type([ - 'type' => 'integer', + 'type' => 'integer', 'message' => 'The value {{ value }} is not a valid {{ type }}.', ])); } diff --git a/reference/constraints/UniqueEntity.rst b/reference/constraints/UniqueEntity.rst index e773e3313d7..15cfe251407 100644 --- a/reference/constraints/UniqueEntity.rst +++ b/reference/constraints/UniqueEntity.rst @@ -51,14 +51,10 @@ your user table: class Author { /** - * @var string $email - * * @ORM\Column(name="email", type="string", length=255, unique=true) * @Assert\Email */ protected $email; - - // ... } .. code-block:: yaml @@ -104,7 +100,7 @@ your user table: public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addConstraint(new UniqueEntity([ - 'fields' => 'email', + 'fields' => 'email', ])); $metadata->addPropertyConstraint('email', new Assert\Email()); @@ -285,9 +281,9 @@ Consider this example: public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addConstraint(new UniqueEntity([ - 'fields' => ['host', 'port'], + 'fields' => ['host', 'port'], 'errorPath' => 'port', - 'message' => 'This port is already in use on that host.', + 'message' => 'This port is already in use on that host.', ])); } } diff --git a/reference/constraints/Url.rst b/reference/constraints/Url.rst index 08583b1196d..9e8e48a1aa9 100644 --- a/reference/constraints/Url.rst +++ b/reference/constraints/Url.rst @@ -35,7 +35,7 @@ Basic Usage /** * @Assert\Url */ - protected $bioUrl; + protected $bioUrl; } .. code-block:: yaml @@ -115,7 +115,7 @@ You can use the following parameters in this message: * message = "The url '{{ value }}' is not a valid url", * ) */ - protected $bioUrl; + protected $bioUrl; } .. code-block:: yaml @@ -187,7 +187,7 @@ the ``ftp://`` type URLs to be valid, redefine the ``protocols`` array, listing * protocols = {"http", "https", "ftp"} * ) */ - protected $bioUrl; + protected $bioUrl; } .. code-block:: yaml @@ -265,7 +265,7 @@ option to the value of any of the ``CHECK_DNS_TYPE_*`` constants in the * checkDNS = "ANY" * ) */ - protected $bioUrl; + protected $bioUrl; } .. code-block:: yaml @@ -338,7 +338,7 @@ DNS check failed. * dnsMessage = "The host '{{ value }}' could not be resolved." * ) */ - protected $bioUrl; + protected $bioUrl; } .. code-block:: yaml diff --git a/reference/constraints/UserPassword.rst b/reference/constraints/UserPassword.rst index 27dc8874c45..dd853e779ab 100644 --- a/reference/constraints/UserPassword.rst +++ b/reference/constraints/UserPassword.rst @@ -46,7 +46,7 @@ the user's current password: * message = "Wrong value for your current password" * ) */ - protected $oldPassword; + protected $oldPassword; } .. code-block:: yaml diff --git a/reference/constraints/Uuid.rst b/reference/constraints/Uuid.rst index 0ca5a5fca33..f89ed1e271c 100644 --- a/reference/constraints/Uuid.rst +++ b/reference/constraints/Uuid.rst @@ -37,7 +37,7 @@ Basic Usage /** * @Assert\Uuid */ - protected $identifier; + protected $identifier; } .. code-block:: yaml diff --git a/reference/constraints/Valid.rst b/reference/constraints/Valid.rst index 1cfa3d21865..97dc22c093d 100644 --- a/reference/constraints/Valid.rst +++ b/reference/constraints/Valid.rst @@ -153,9 +153,6 @@ stores an ``Address`` instance in the ``$address`` property:: class Address { - protected $street; - protected $zipCode; - public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('street', new Assert\NotBlank()); @@ -172,10 +169,6 @@ stores an ``Address`` instance in the ``$address`` property:: class Author { - protected $firstName; - protected $lastName; - protected $address; - public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('firstName', new Assert\NotBlank()); @@ -238,8 +231,6 @@ an invalid address. To prevent that, add the ``Valid`` constraint to the class Author { - protected $address; - public static function loadValidatorMetadata(ClassMetadata $metadata) { $metadata->addPropertyConstraint('address', new Assert\Valid());