From 131a287b3d371cdc37ff1c3c3dbcfe9dd35432a3 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sun, 30 Dec 2012 23:06:43 +0100 Subject: [PATCH 1/2] Added missing formats --- reference/constraints/File.rst | 1 + reference/constraints/Min.rst | 31 +++++++++++++++++++++++++++++++ reference/constraints/Regex.rst | 20 ++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/reference/constraints/File.rst b/reference/constraints/File.rst index 96c9f6e16e2..de15ff6d4c7 100644 --- a/reference/constraints/File.rst +++ b/reference/constraints/File.rst @@ -120,6 +120,7 @@ below a certain file size and a valid PDF, add the following: // src/Acme/BlogBundle/Entity/Author.php namespace Acme\BlogBundle\Entity; + // ... use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Constraints\File; diff --git a/reference/constraints/Min.rst b/reference/constraints/Min.rst index a51178e13be..794297fedd2 100644 --- a/reference/constraints/Min.rst +++ b/reference/constraints/Min.rst @@ -46,6 +46,37 @@ the following: protected $age; } + .. code-block:: xml + + + + + + + + + + + + .. code-block:: php + + // src/Acme/EventBundle/Entity/Participant.php + namespace Acme\EventBundle\Entity\Participant; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Participant + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('age', new Assert\Min(array( + 'limit' => '18', + 'message' => 'You must be 18 or older to enter', + )); + } + } + Options ------- diff --git a/reference/constraints/Regex.rst b/reference/constraints/Regex.rst index d3f02426685..426bd72f196 100644 --- a/reference/constraints/Regex.rst +++ b/reference/constraints/Regex.rst @@ -127,6 +127,26 @@ message: + .. code-block:: php + + // src/Acme/BlogBundle/Entity/Author.php + namespace Acme\BlogBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('firstName', new Assert\Regex(array( + 'pattern' => '/\d/', + 'match' => false, + 'message' => 'Your name cannot contain a number', + ))); + } + } + Options ------- From 3fd621109b0240fc8ac9552d3c2abefb0221b8ee Mon Sep 17 00:00:00 2001 From: WouterJ Date: Tue, 5 Feb 2013 17:09:29 +0100 Subject: [PATCH 2/2] Fixed interpunction, thanks to @ricardclau --- reference/constraints/Min.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/reference/constraints/Min.rst b/reference/constraints/Min.rst index 794297fedd2..af37ac956d2 100644 --- a/reference/constraints/Min.rst +++ b/reference/constraints/Min.rst @@ -41,7 +41,7 @@ the following: class Participant { /** - * @Assert\Min(limit = "18", message = "You must be 18 or older to enter") + * @Assert\Min(limit = "18", message = "You must be 18 or older to enter.") */ protected $age; } @@ -53,7 +53,7 @@ the following: - + @@ -72,7 +72,7 @@ the following: { $metadata->addPropertyConstraint('age', new Assert\Min(array( 'limit' => '18', - 'message' => 'You must be 18 or older to enter', + 'message' => 'You must be 18 or older to enter.', )); } }