merged branch jalliot/missing-guessers (PR #2306)

Commits
-------

ee0fe7a Added guessers for Size and SizeLength constraints

Discussion
----------

Added guessers for Size and SizeLength constraints

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

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

by jalliot at 2011/09/30 13:40:37 -0700

BTW, I've noticed that some constraints currently don't have guessers in 2.0:

* ``False`` (which could be guessed as a checkbox)
* ``True`` (which could be guessed as a required checkbox)
* ``Choice`` (which could be guessed as a choice type with medium confidence and with the choice list being guessed as the list provided for the constraint)

Are there any reasons why this is not implemented in 2.0 or should I try to make a PR for it?

There is also the ``Collection`` case but I guess it would be too difficult for this one...
This commit is contained in:
Fabien Potencier 2011-09-30 23:05:31 +02:00
commit c78921f0d3

View File

@ -220,6 +220,18 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
array(),
Guess::HIGH_CONFIDENCE
);
case 'Symfony\Component\Validator\Constraints\Size':
return new TypeGuess(
'number',
array(),
Guess::LOW_CONFIDENCE
);
case 'Symfony\Component\Validator\Constraints\SizeLength':
return new TypeGuess(
'text',
array(),
Guess::LOW_CONFIDENCE
);
}
}
@ -269,6 +281,16 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
strlen((string)$constraint->limit),
Guess::HIGH_CONFIDENCE
);
case 'Symfony\Component\Validator\Constraints\SizeLength':
return new ValueGuess(
$constraint->max,
Guess::HIGH_CONFIDENCE
);
case 'Symfony\Component\Validator\Constraints\Size':
return new ValueGuess(
strlen((string)$constraint->max),
Guess::HIGH_CONFIDENCE
);
}
}
@ -291,6 +313,16 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
strlen((string)$constraint->limit),
Guess::HIGH_CONFIDENCE
);
case 'Symfony\Component\Validator\Constraints\SizeLength':
return new ValueGuess(
$constraint->min,
Guess::HIGH_CONFIDENCE
);
case 'Symfony\Component\Validator\Constraints\Size':
return new ValueGuess(
strlen((string)$constraint->min),
Guess::HIGH_CONFIDENCE
);
}
}