Skip to content

Commit bdda1c6

Browse files
committed
fix if entity is proxy
1 parent 597f5c2 commit bdda1c6

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/DoctrineIdentityExtractor.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Utilitte\Doctrine;
44

5+
use Doctrine\Common\Proxy\Proxy;
56
use Doctrine\ORM\EntityManagerInterface;
67
use InvalidArgumentException;
78
use LogicException;
@@ -90,17 +91,15 @@ public function extractIdentityMany(iterable $entities, bool $allowMixing = fals
9091
);
9192
}
9293

93-
$className = get_class($entity);
94-
95-
if (!$className) {
96-
throw new LogicException('Cannot get class name');
97-
}
98-
9994
if (!$allowMixing) {
10095
if (!$type) {
101-
$type = $className;
96+
$type = get_class($entity);
97+
98+
if (!$type) {
99+
throw new LogicException('Cannot get class name');
100+
}
102101
} else {
103-
$this->checkType($className, $type);
102+
$this->checkType($entity, $type);
104103
}
105104
}
106105

@@ -110,11 +109,11 @@ public function extractIdentityMany(iterable $entities, bool $allowMixing = fals
110109
return $ids;
111110
}
112111

113-
private function checkType(string $class, string $type): void
112+
private function checkType(object $entity, string $type): void
114113
{
115-
if ($type !== $class) {
114+
if (get_class($entity) !== $type && !$entity instanceof Proxy && get_parent_class($entity) !== $type) {
116115
throw new InvalidArgumentException(
117-
sprintf('Given array must be an array of %s, %s contained in array', $type, $class)
116+
sprintf('Given array must be an array of %s, %s contained in array', $type, $entity)
118117
);
119118
}
120119
}

0 commit comments

Comments
 (0)