[Validator] add getConstraints to MetadataInterface

This commit is contained in:
Tobias Schultze 2014-08-20 16:09:22 +02:00
parent 04eb61b80e
commit 14d3f97488
7 changed files with 16 additions and 31 deletions

View File

@ -17,7 +17,6 @@ use Symfony\Component\Form\Guess\TypeGuess;
use Symfony\Component\Form\Guess\ValueGuess; use Symfony\Component\Form\Guess\ValueGuess;
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Mapping\ClassMetadataInterface; use Symfony\Component\Validator\Mapping\ClassMetadataInterface;
use Symfony\Component\Validator\Mapping\GenericMetadata;
use Symfony\Component\Validator\MetadataFactoryInterface; use Symfony\Component\Validator\MetadataFactoryInterface;
class ValidatorTypeGuesser implements FormTypeGuesserInterface class ValidatorTypeGuesser implements FormTypeGuesserInterface
@ -270,10 +269,6 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
$memberMetadatas = $classMetadata->getPropertyMetadata($property); $memberMetadatas = $classMetadata->getPropertyMetadata($property);
foreach ($memberMetadatas as $memberMetadata) { foreach ($memberMetadatas as $memberMetadata) {
if (!$memberMetadata instanceof GenericMetadata) {
continue;
}
$constraints = $memberMetadata->getConstraints(); $constraints = $memberMetadata->getConstraints();
foreach ($constraints as $constraint) { foreach ($constraints as $constraint) {

View File

@ -11,6 +11,7 @@ CHANGELOG
* deprecated `ClassMetadata::hasMemberMetadatas()` * deprecated `ClassMetadata::hasMemberMetadatas()`
* deprecated `ClassMetadata::getMemberMetadatas()` * deprecated `ClassMetadata::getMemberMetadatas()`
* deprecated `ClassMetadata::addMemberMetadata()` * deprecated `ClassMetadata::addMemberMetadata()`
* [BC BREAK] added `Mapping\MetadataInterface::getConstraints()`
2.5.0 2.5.0
----- -----

View File

@ -89,7 +89,7 @@ class ExecutionContext implements ExecutionContextInterface
/** /**
* The current validation metadata. * The current validation metadata.
* *
* @var MetadataInterface * @var MetadataInterface|null
*/ */
private $metadata; private $metadata;

View File

@ -319,10 +319,8 @@ class ClassMetadata extends ElementMetadata implements LegacyMetadataInterface,
foreach ($source->getPropertyMetadata($property) as $member) { foreach ($source->getPropertyMetadata($property) as $member) {
$member = clone $member; $member = clone $member;
if ($member instanceof GenericMetadata) { foreach ($member->getConstraints() as $constraint) {
foreach ($member->getConstraints() as $constraint) { $constraint->addImplicitGroupName($this->getDefaultGroup());
$constraint->addImplicitGroupName($this->getDefaultGroup());
}
} }
$this->addPropertyMetadata($member); $this->addPropertyMetadata($member);

View File

@ -74,7 +74,7 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface
} }
/** /**
* Returns the metadata for the given class name or object. * {@inheritdoc}
* *
* If the method was called with the same class name (or an object of that * If the method was called with the same class name (or an object of that
* class) before, the same metadata instance is returned. * class) before, the same metadata instance is returned.
@ -87,12 +87,6 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface
* configured with a loader, the metadata is passed to the * configured with a loader, the metadata is passed to the
* {@link LoaderInterface::loadClassMetadata()} method for further * {@link LoaderInterface::loadClassMetadata()} method for further
* configuration. At last, the new object is returned. * configuration. At last, the new object is returned.
*
* @param string|object $value A class name or an object
*
* @return MetadataInterface The metadata for the value
*
* @throws NoSuchMetadataException If no metadata exists for the given value
*/ */
public function getMetadataFor($value) public function getMetadataFor($value)
{ {
@ -141,12 +135,7 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface
} }
/** /**
* Returns whether the factory is able to return metadata for the given * {@inheritdoc}
* class name or object.
*
* @param string|object $value A class name or an object
*
* @return bool Whether metadata can be returned for that class
*/ */
public function hasMetadataFor($value) public function hasMetadataFor($value)
{ {

View File

@ -180,9 +180,7 @@ class GenericMetadata implements MetadataInterface
} }
/** /**
* Returns all constraints of this element. * {@inheritdoc}
*
* @return Constraint[] A list of Constraint instances
*/ */
public function getConstraints() public function getConstraints()
{ {
@ -200,12 +198,9 @@ class GenericMetadata implements MetadataInterface
} }
/** /**
* Returns the constraints of the given group and global ones (* group). * {@inheritdoc}
* *
* @param string $group The group name * Aware of the global group (* group).
*
* @return Constraint[] An list of all the Constraint instances belonging
* to the group
*/ */
public function findConstraints($group) public function findConstraints($group)
{ {

View File

@ -48,4 +48,11 @@ interface MetadataInterface extends LegacyMetadataInterface
* @see TraversalStrategy * @see TraversalStrategy
*/ */
public function getTraversalStrategy(); public function getTraversalStrategy();
/**
* Returns all constraints of this element.
*
* @return Constraint[] A list of Constraint instances
*/
public function getConstraints();
} }