[Validator] Add check for existing metadata on property
This commit is contained in:
parent
60cf0aa181
commit
4cbdbcb1f9
@ -301,6 +301,14 @@ class ClassMetadata extends ElementMetadata implements MetadataInterface, ClassB
|
||||
return $this->members[$property];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasPropertyMetadata($property)
|
||||
{
|
||||
return array_key_exists($property, $this->members);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -18,6 +18,15 @@ namespace Symfony\Component\Validator;
|
||||
*/
|
||||
interface PropertyMetadataContainerInterface
|
||||
{
|
||||
/**
|
||||
* Check if there's any metadata attached to the given named property.
|
||||
*
|
||||
* @param string $property The property name.
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
public function hasPropertyMetadata($property);
|
||||
|
||||
/**
|
||||
* Returns all metadata instances for the given named property.
|
||||
*
|
||||
|
@ -187,6 +187,10 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$result = $this->validator->validateProperty($entity, 'firstName');
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
|
||||
$result = $this->validator->validateProperty($entity, 'lastName');
|
||||
|
||||
$this->assertCount(0, $result);
|
||||
}
|
||||
|
||||
public function testValidatePropertyValue()
|
||||
|
@ -112,6 +112,10 @@ class Validator implements ValidatorInterface
|
||||
}
|
||||
|
||||
foreach ($this->resolveGroups($groups) as $group) {
|
||||
if (!$metadata->hasPropertyMetadata($property)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($metadata->getPropertyMetadata($property) as $propMeta) {
|
||||
$propMeta->accept($visitor, $propMeta->getPropertyValue($containingValue), $group, $property);
|
||||
}
|
||||
@ -139,6 +143,10 @@ class Validator implements ValidatorInterface
|
||||
}
|
||||
|
||||
foreach ($this->resolveGroups($groups) as $group) {
|
||||
if (!$metadata->hasPropertyMetadata($property)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($metadata->getPropertyMetadata($property) as $propMeta) {
|
||||
$propMeta->accept($visitor, $value, $group, $property);
|
||||
}
|
||||
|
Reference in New Issue
Block a user