Skip to content

Commit ac0c49e

Browse files
committed
Use correct default repositoryClass if the user doesnt set it
1 parent aec1b82 commit ac0c49e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

extension.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
parameters:
22
doctrine:
3-
repositoryClass: Doctrine\ORM\EntityRepository
3+
repositoryClass: null
44
allCollectionsSelectable: true
55
objectManagerLoader: null
66

src/Type/Doctrine/ObjectMetadataResolver.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ final class ObjectMetadataResolver
1818
/** @var string */
1919
private $repositoryClass;
2020

21-
public function __construct(?string $objectManagerLoader, string $repositoryClass)
21+
public function __construct(?string $objectManagerLoader, ?string $repositoryClass)
2222
{
2323
if ($objectManagerLoader !== null) {
2424
$this->objectManager = $this->getObjectManager($objectManagerLoader);
2525
}
26-
$this->repositoryClass = $repositoryClass;
26+
if ($repositoryClass !== null) {
27+
$this->repositoryClass = $repositoryClass;
28+
} elseif ($this->objectManager !== null && get_class($this->objectManager) === 'Doctrine\ODM\MongoDB\DocumentManager') {
29+
$this->repositoryClass = 'Doctrine\ODM\MongoDB\DocumentRepository';
30+
} else {
31+
$this->repositoryClass = 'Doctrine\ORM\EntityRepository';
32+
}
2733
}
2834

2935
private function getObjectManager(string $objectManagerLoader): ObjectManager
@@ -44,11 +50,11 @@ public function getRepositoryClass(string $className): string
4450
$metadata = $this->objectManager->getClassMetadata($className);
4551

4652
if ($metadata instanceof ORMMetadata) {
47-
return $metadata->customRepositoryClassName ?? 'Doctrine\ORM\EntityRepository';
53+
return $metadata->customRepositoryClassName ?? $this->repositoryClass;
4854
}
4955

5056
if ($metadata instanceof ODMMetadata) {
51-
return $metadata->customRepositoryClassName ?? 'Doctrine\ODM\MongoDB\DocumentRepository';
57+
return $metadata->customRepositoryClassName ?? $this->repositoryClass;
5258
}
5359

5460
return $this->repositoryClass;

0 commit comments

Comments
 (0)