merged branch hhamon/type_validator_fix (PR #2379)

Commits
-------

73312ab [Validator] The Type constraint now accepts the "Boolean" type instead of "boolean".

Discussion
----------

[Validator] The Type constraint now accepts the "Boolean" type instead of

[Validator] The Type constraint now accepts the "Boolean" type instead of "boolean".

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -

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

by stloyd at 2011/10/11 03:43:24 -0700

As this is bugfix only, this should be made againts __2.0__ branch.

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

by hhamon at 2011/10/11 05:03:52 -0700

@stloyd I don't really know if it's a bug fix or an improvement. We could not use "Boolean" but we could use "boolean" or "bool" only. So that's why I just improved this constraint validator.
This commit is contained in:
Fabien Potencier 2011-10-15 03:12:16 +02:00
commit 3bbb6e5993
2 changed files with 4 additions and 1 deletions

View File

@ -35,7 +35,8 @@ class TypeValidator extends ConstraintValidator
return true;
}
$type = $constraint->type == 'boolean' ? 'bool' : $constraint->type;
$type = strtolower($constraint->type);
$type = $type == 'boolean' ? 'bool' : $constraint->type;
$function = 'is_'.$type;
if (function_exists($function) && call_user_func($function, $value)) {

View File

@ -62,6 +62,8 @@ class TypeValidatorTest extends \PHPUnit_Framework_TestCase
$file = $this->createFile();
return array(
array(true, 'Boolean'),
array(false, 'Boolean'),
array(true, 'boolean'),
array(false, 'boolean'),
array(true, 'bool'),