Skip to content

Commit 41ace4f

Browse files
authored
Update DoctrineEntityHydrationExtension.php, support for interface aliased to an entity
Doctrine have the feature to use interface aliased to a concrete entity class. This PR propose a small modification to ensure that is will also supported by the doctrine hydrator
1 parent 9d7ec20 commit 41ace4f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/LiveComponent/src/Hydration/DoctrineEntityHydrationExtension.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,21 @@ public function dehydrate(object $object): mixed
8181

8282
private function objectManagerFor(string $class): ?ObjectManager
8383
{
84-
if (!class_exists($class)) {
84+
if (!interface_exist($class) && !class_exists($class)) {
8585
return null;
8686
}
8787

8888
// todo cache/warmup an array of classes that are "doctrine objects"
8989
foreach ($this->managerRegistries as $registry) {
90-
if ($om = $registry->getManagerForClass($class)) {
91-
return self::ensureManagedObject($om, $class);
90+
foreach($registry->getManagers() as $om) {
91+
// this way, it resolves the interface
92+
if ($om->getClassMetadata($class)) {
93+
return self::ensureManagedObject($om, $class);
94+
}
9295
}
96+
// if ($om = $registry->getManagerForClass($class)) {
97+
// return self::ensureManagedObject($om, $class);
98+
// }
9399
}
94100

95101
return null;

0 commit comments

Comments
 (0)