@@ -18,12 +18,18 @@ final class ObjectMetadataResolver
18
18
/** @var string */
19
19
private $ repositoryClass ;
20
20
21
- public function __construct (?string $ objectManagerLoader , string $ repositoryClass )
21
+ public function __construct (?string $ objectManagerLoader , ? string $ repositoryClass )
22
22
{
23
23
if ($ objectManagerLoader !== null ) {
24
24
$ this ->objectManager = $ this ->getObjectManager ($ objectManagerLoader );
25
25
}
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
+ }
27
33
}
28
34
29
35
private function getObjectManager (string $ objectManagerLoader ): ObjectManager
@@ -44,11 +50,11 @@ public function getRepositoryClass(string $className): string
44
50
$ metadata = $ this ->objectManager ->getClassMetadata ($ className );
45
51
46
52
if ($ metadata instanceof ORMMetadata) {
47
- return $ metadata ->customRepositoryClassName ?? ' Doctrine\ORM\EntityRepository ' ;
53
+ return $ metadata ->customRepositoryClassName ?? $ this -> repositoryClass ;
48
54
}
49
55
50
56
if ($ metadata instanceof ODMMetadata) {
51
- return $ metadata ->customRepositoryClassName ?? ' Doctrine\ODM\MongoDB\DocumentRepository ' ;
57
+ return $ metadata ->customRepositoryClassName ?? $ this -> repositoryClass ;
52
58
}
53
59
54
60
return $ this ->repositoryClass ;
0 commit comments