merged branch Seldaek/validator_yaml (PR #3794)
Commits -------8ceb569
Fix typo8702ea5
[Validator] Allow empty keys in the validation config Discussion ---------- [Validator] Allow empty keys in the validation config This allows you to just list fields that don't have validation rules (yet), for future reference it's kinda helpful. Right now if they're not commented out a fatal is thrown because null isn't an array. --------------------------------------------------------------------------- by bschussek at 2012-04-05T15:34:09Z Could you add a test please? --------------------------------------------------------------------------- by Seldaek at 2012-04-05T15:34:48Z The dummy key I added in the test makes it fail without the fix. --------------------------------------------------------------------------- by bschussek at 2012-04-05T15:46:54Z Ah, that's perfect, I overlooked that. Thanks!
This commit is contained in:
commit
37c9fe9a2b
@ -58,24 +58,28 @@ class YamlFileLoader extends FileLoader
|
||||
$metadata->setGroupSequenceProvider((bool)$yaml['group_sequence_provider']);
|
||||
}
|
||||
|
||||
if (isset($yaml['constraints'])) {
|
||||
if (isset($yaml['constraints']) && is_array($yaml['constraints'])) {
|
||||
foreach ($this->parseNodes($yaml['constraints']) as $constraint) {
|
||||
$metadata->addConstraint($constraint);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($yaml['properties'])) {
|
||||
if (isset($yaml['properties']) && is_array($yaml['properties'])) {
|
||||
foreach ($yaml['properties'] as $property => $constraints) {
|
||||
foreach ($this->parseNodes($constraints) as $constraint) {
|
||||
$metadata->addPropertyConstraint($property, $constraint);
|
||||
if (null !== $constraints) {
|
||||
foreach ($this->parseNodes($constraints) as $constraint) {
|
||||
$metadata->addPropertyConstraint($property, $constraint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($yaml['getters'])) {
|
||||
if (isset($yaml['getters']) && is_array($yaml['getters'])) {
|
||||
foreach ($yaml['getters'] as $getter => $constraints) {
|
||||
foreach ($this->parseNodes($constraints) as $constraint) {
|
||||
$metadata->addGetterConstraint($getter, $constraint);
|
||||
if (null !== $constraints) {
|
||||
foreach ($this->parseNodes($constraints) as $constraint) {
|
||||
$metadata->addGetterConstraint($getter, $constraint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ Symfony\Component\Validator\Tests\Fixtures\Entity:
|
||||
- Min: 5
|
||||
# Constraint with options
|
||||
- Choice: { choices: [A, B], message: Must be one of %choices% }
|
||||
dummy:
|
||||
|
||||
getters:
|
||||
lastName:
|
||||
|
Reference in New Issue
Block a user