[Validator] add getConstraints to MetadataInterface
This commit is contained in:
parent
04eb61b80e
commit
14d3f97488
@ -17,7 +17,6 @@ use Symfony\Component\Form\Guess\TypeGuess;
|
||||
use Symfony\Component\Form\Guess\ValueGuess;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadataInterface;
|
||||
use Symfony\Component\Validator\Mapping\GenericMetadata;
|
||||
use Symfony\Component\Validator\MetadataFactoryInterface;
|
||||
|
||||
class ValidatorTypeGuesser implements FormTypeGuesserInterface
|
||||
@ -270,10 +269,6 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
|
||||
$memberMetadatas = $classMetadata->getPropertyMetadata($property);
|
||||
|
||||
foreach ($memberMetadatas as $memberMetadata) {
|
||||
if (!$memberMetadata instanceof GenericMetadata) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$constraints = $memberMetadata->getConstraints();
|
||||
|
||||
foreach ($constraints as $constraint) {
|
||||
|
@ -11,6 +11,7 @@ CHANGELOG
|
||||
* deprecated `ClassMetadata::hasMemberMetadatas()`
|
||||
* deprecated `ClassMetadata::getMemberMetadatas()`
|
||||
* deprecated `ClassMetadata::addMemberMetadata()`
|
||||
* [BC BREAK] added `Mapping\MetadataInterface::getConstraints()`
|
||||
|
||||
2.5.0
|
||||
-----
|
||||
|
@ -89,7 +89,7 @@ class ExecutionContext implements ExecutionContextInterface
|
||||
/**
|
||||
* The current validation metadata.
|
||||
*
|
||||
* @var MetadataInterface
|
||||
* @var MetadataInterface|null
|
||||
*/
|
||||
private $metadata;
|
||||
|
||||
|
@ -319,10 +319,8 @@ class ClassMetadata extends ElementMetadata implements LegacyMetadataInterface,
|
||||
foreach ($source->getPropertyMetadata($property) as $member) {
|
||||
$member = clone $member;
|
||||
|
||||
if ($member instanceof GenericMetadata) {
|
||||
foreach ($member->getConstraints() as $constraint) {
|
||||
$constraint->addImplicitGroupName($this->getDefaultGroup());
|
||||
}
|
||||
foreach ($member->getConstraints() as $constraint) {
|
||||
$constraint->addImplicitGroupName($this->getDefaultGroup());
|
||||
}
|
||||
|
||||
$this->addPropertyMetadata($member);
|
||||
|
@ -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
|
||||
* 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
|
||||
* {@link LoaderInterface::loadClassMetadata()} method for further
|
||||
* 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)
|
||||
{
|
||||
@ -141,12 +135,7 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the factory is able to return metadata for the given
|
||||
* class name or object.
|
||||
*
|
||||
* @param string|object $value A class name or an object
|
||||
*
|
||||
* @return bool Whether metadata can be returned for that class
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasMetadataFor($value)
|
||||
{
|
||||
|
@ -180,9 +180,7 @@ class GenericMetadata implements MetadataInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all constraints of this element.
|
||||
*
|
||||
* @return Constraint[] A list of Constraint instances
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @return Constraint[] An list of all the Constraint instances belonging
|
||||
* to the group
|
||||
* Aware of the global group (* group).
|
||||
*/
|
||||
public function findConstraints($group)
|
||||
{
|
||||
|
@ -48,4 +48,11 @@ interface MetadataInterface extends LegacyMetadataInterface
|
||||
* @see TraversalStrategy
|
||||
*/
|
||||
public function getTraversalStrategy();
|
||||
|
||||
/**
|
||||
* Returns all constraints of this element.
|
||||
*
|
||||
* @return Constraint[] A list of Constraint instances
|
||||
*/
|
||||
public function getConstraints();
|
||||
}
|
||||
|
Reference in New Issue
Block a user