bug #28252 [DoctrineBridge] support __toString as documented for UniqueEntityValidator (dmaicher)
This PR was squashed before being merged into the 3.4 branch (closes #28252).
Discussion
----------
[DoctrineBridge] support __toString as documented for UniqueEntityValidator
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #28245
| License | MIT
| Doc PR | -
This fixes https://github.com/symfony/symfony/issues/28245.
It brings back handling `__toString` as documented for invalid values.
Commits
-------
2ac883a99b
[DoctrineBridge] support __toString as documented for UniqueEntityValidator
This commit is contained in:
commit
d446b6aefb
@ -482,7 +482,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
$this->buildViolation('myMessage')
|
$this->buildViolation('myMessage')
|
||||||
->atPath('property.path.single')
|
->atPath('property.path.single')
|
||||||
->setParameter('{{ value }}', 'object("Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity") identified by (id => 1)')
|
->setParameter('{{ value }}', 'foo')
|
||||||
->setInvalidValue($entity1)
|
->setInvalidValue($entity1)
|
||||||
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
|
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
|
||||||
->setCause(array($associated, $associated2))
|
->setCause(array($associated, $associated2))
|
||||||
|
@ -186,6 +186,10 @@ class UniqueEntityValidator extends ConstraintValidator
|
|||||||
return $this->formatValue($value, self::PRETTY_DATE);
|
return $this->formatValue($value, self::PRETTY_DATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (\method_exists($value, '__toString')) {
|
||||||
|
return (string) $value;
|
||||||
|
}
|
||||||
|
|
||||||
if ($class->getName() !== $idClass = \get_class($value)) {
|
if ($class->getName() !== $idClass = \get_class($value)) {
|
||||||
// non unique value might be a composite PK that consists of other entity objects
|
// non unique value might be a composite PK that consists of other entity objects
|
||||||
if ($em->getMetadataFactory()->hasMetadataFor($idClass)) {
|
if ($em->getMetadataFactory()->hasMetadataFor($idClass)) {
|
||||||
|
Reference in New Issue
Block a user