Skip to content

Commit

Permalink
Merge pull request #2214 from WouterJ/constraint_formats
Browse files Browse the repository at this point in the history
[Constraints] Added missing formats
  • Loading branch information
weaverryan committed Feb 14, 2013
2 parents 7c9d47a + 3fd6211 commit 6a4d1c4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions reference/constraints/File.rst
Expand Up @@ -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;
Expand Down
33 changes: 32 additions & 1 deletion reference/constraints/Min.rst
Expand Up @@ -41,11 +41,42 @@ 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;
}
.. code-block:: xml
<!-- src/Acme/EventBundle/Resources/config/validation.yml -->
<class name="Acme\EventBundle\Entity\Participant">
<property name="age">
<constraint name="Min">
<option name="limit">18</option>
<option name="message">You must be 18 or older to enter.</option>
</constraint>
</property>
</class>
.. 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
-------

Expand Down
20 changes: 20 additions & 0 deletions reference/constraints/Regex.rst
Expand Up @@ -127,6 +127,26 @@ message:
</property>
</class>
.. 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
-------

Expand Down

0 comments on commit 6a4d1c4

Please sign in to comment.