Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 97d564e

Browse filesBrowse files
committed
fix compatibility with Doctrine ORM 4
1 parent f35f975 commit 97d564e
Copy full SHA for 97d564e

File tree

Expand file treeCollapse file tree

2 files changed

+17
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-2
lines changed

‎src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Doctrine\ORM\EntityRepository;
1717
use Doctrine\ORM\Mapping\ClassMetadata;
1818
use Doctrine\ORM\Mapping\ClassMetadataInfo;
19+
use Doctrine\ORM\Mapping\PropertyAccessors\RawValuePropertyAccessor;
1920
use Doctrine\ORM\Tools\SchemaTool;
2021
use Doctrine\Persistence\ManagerRegistry;
2122
use Doctrine\Persistence\ObjectManager;
@@ -115,11 +116,21 @@ class_exists(ClassMetadataInfo::class) ? ClassMetadataInfo::class : ClassMetadat
115116
->willReturn(true)
116117
;
117118
$refl = $this->createMock(\ReflectionProperty::class);
119+
$refl
120+
->method('getName')
121+
->willReturn('name')
122+
;
118123
$refl
119124
->method('getValue')
120125
->willReturn(true)
121126
;
122-
$classMetadata->reflFields = ['name' => $refl];
127+
128+
if (property_exists(ClassMetadata::class, 'propertyAccessors')) {
129+
$classMetadata->propertyAccessors['name'] = RawValuePropertyAccessor::fromReflectionProperty($refl);
130+
} else {
131+
$classMetadata->reflFields = ['name' => $refl];
132+
}
133+
123134
$em->expects($this->any())
124135
->method('getClassMetadata')
125136
->willReturn($classMetadata)

‎src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ public function validate(mixed $entity, Constraint $constraint)
9292
throw new ConstraintDefinitionException(sprintf('The field "%s" is not mapped by Doctrine, so it cannot be validated for uniqueness.', $fieldName));
9393
}
9494

95-
$fieldValue = $class->reflFields[$fieldName]->getValue($entity);
95+
if (property_exists(ClassMetadata::class, 'propertyAccessors')) {
96+
$fieldValue = $class->propertyAccessors[$fieldName]->getValue($entity);
97+
} else {
98+
$fieldValue = $class->reflFields[$fieldName]->getValue($entity);
99+
}
96100

97101
if (null === $fieldValue && $this->ignoreNullForField($constraint, $fieldName)) {
98102
$hasIgnorableNullValue = true;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.