Commit eb15c4b4 authored by Fabien Potencier's avatar Fabien Potencier

merged branch spectralsun/master (PR #617)

This PR was merged into the master branch.

Commits
-------

ef85340f Fixed brace and spaces
6ec11533 Changed Assert\MinLength to Assert\Length in doc

Discussion
----------

Removed Assert\minLength in doc

Changed to Assert\Length

---------------------------------------------------------------------------

by igorw at 2013-02-05T00:10:22Z

For the record, this change is due to Assert\MinLength and MaxLength being deprecated in 2.1, in favour of Length.

---------------------------------------------------------------------------

by igorw at 2013-02-05T00:16:47Z

👍

---------------------------------------------------------------------------

by fabpot at 2013-02-07T11:22:31Z

As we still support 2.1 and 2.2, I would suggest to add a note to indicate the name of the constraint in 2.1.

---------------------------------------------------------------------------

by igorw at 2013-02-11T14:23:51Z

@fabpot Length is already available in 2.1. There is no reason not to use it already. This PR looks good to me.
parents 28e87dac ef85340f
...@@ -150,7 +150,7 @@ form by adding constraints on the fields:: ...@@ -150,7 +150,7 @@ form by adding constraints on the fields::
$form = $app['form.factory']->createBuilder('form') $form = $app['form.factory']->createBuilder('form')
->add('name', 'text', array( ->add('name', 'text', array(
'constraints' => array(new Assert\NotBlank(), new Assert\MinLength(5)) 'constraints' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 5)))
)) ))
->add('email', 'text', array( ->add('email', 'text', array(
'constraints' => new Assert\Email() 'constraints' => new Assert\Email()
......
...@@ -99,10 +99,10 @@ collection of constraints:: ...@@ -99,10 +99,10 @@ collection of constraints::
); );
$constraint = new Assert\Collection(array( $constraint = new Assert\Collection(array(
'title' => new Assert\MinLength(10), 'title' => new Assert\Length(array('min' => 10)),
'author' => new Assert\Collection(array( 'author' => new Assert\Collection(array(
'first_name' => array(new Assert\NotBlank(), new Assert\MinLength(10)), 'first_name' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 10))),
'last_name' => new Assert\MinLength(10), 'last_name' => new Assert\Length(array('min' => 10)),
)), )),
)); ));
$errors = $app['validator']->validateValue($book, $constraint); $errors = $app['validator']->validateValue($book, $constraint);
...@@ -133,11 +133,11 @@ the class properties and getters, and then call the ``validate`` method:: ...@@ -133,11 +133,11 @@ the class properties and getters, and then call the ``validate`` method::
$metadata = $app['validator.mapping.class_metadata_factory']->getClassMetadata('Author'); $metadata = $app['validator.mapping.class_metadata_factory']->getClassMetadata('Author');
$metadata->addPropertyConstraint('first_name', new Assert\NotBlank()); $metadata->addPropertyConstraint('first_name', new Assert\NotBlank());
$metadata->addPropertyConstraint('first_name', new Assert\MinLength(10)); $metadata->addPropertyConstraint('first_name', new Assert\Length(array('min' => 10)));
$metadata->addPropertyConstraint('last_name', new Assert\MinLength(10)); $metadata->addPropertyConstraint('last_name', new Assert\Length(array('min' => 10)));
$metadata = $app['validator.mapping.class_metadata_factory']->getClassMetadata('Book'); $metadata = $app['validator.mapping.class_metadata_factory']->getClassMetadata('Book');
$metadata->addPropertyConstraint('title', new Assert\MinLength(10)); $metadata->addPropertyConstraint('title', new Assert\Length(array('min' => 10)));
$metadata->addPropertyConstraint('author', new Assert\Valid()); $metadata->addPropertyConstraint('author', new Assert\Valid());
$errors = $app['validator']->validate($book); $errors = $app['validator']->validate($book);
...@@ -163,7 +163,7 @@ You can also declare the class constraint by adding a static ...@@ -163,7 +163,7 @@ You can also declare the class constraint by adding a static
static public function loadValidatorMetadata(ClassMetadata $metadata) static public function loadValidatorMetadata(ClassMetadata $metadata)
{ {
$metadata->addPropertyConstraint('title', new Assert\MinLength(10)); $metadata->addPropertyConstraint('title', new Assert\Length(array('min' => 10)));
$metadata->addPropertyConstraint('author', new Assert\Valid()); $metadata->addPropertyConstraint('author', new Assert\Valid());
} }
} }
...@@ -176,8 +176,8 @@ You can also declare the class constraint by adding a static ...@@ -176,8 +176,8 @@ You can also declare the class constraint by adding a static
static public function loadValidatorMetadata(ClassMetadata $metadata) static public function loadValidatorMetadata(ClassMetadata $metadata)
{ {
$metadata->addPropertyConstraint('first_name', new Assert\NotBlank()); $metadata->addPropertyConstraint('first_name', new Assert\NotBlank());
$metadata->addPropertyConstraint('first_name', new Assert\MinLength(10)); $metadata->addPropertyConstraint('first_name', new Assert\Length(array('min' => 10)));
$metadata->addPropertyConstraint('last_name', new Assert\MinLength(10)); $metadata->addPropertyConstraint('last_name', new Assert\Length(array('min' => 10)));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment