4
4
5
5
namespace Doctrine \ORM \Repository ;
6
6
7
- use Doctrine \Deprecations \Deprecation ;
8
7
use Doctrine \ORM \EntityManagerInterface ;
9
8
use Doctrine \ORM \EntityRepository ;
10
9
use Doctrine \Persistence \ObjectRepository ;
@@ -20,22 +19,15 @@ final class DefaultRepositoryFactory implements RepositoryFactory
20
19
* The list of EntityRepository instances.
21
20
*
22
21
* @var ObjectRepository[]
23
- * @psalm-var array<string, ObjectRepository >
22
+ * @psalm-var array<string, EntityRepository >
24
23
*/
25
- private $ repositoryList = [];
24
+ private array $ repositoryList = [];
26
25
27
- /**
28
- * {@inheritdoc}
29
- */
30
- public function getRepository (EntityManagerInterface $ entityManager , $ entityName ): ObjectRepository
26
+ public function getRepository (EntityManagerInterface $ entityManager , string $ entityName ): EntityRepository
31
27
{
32
28
$ repositoryHash = $ entityManager ->getClassMetadata ($ entityName )->getName () . spl_object_id ($ entityManager );
33
29
34
- if (isset ($ this ->repositoryList [$ repositoryHash ])) {
35
- return $ this ->repositoryList [$ repositoryHash ];
36
- }
37
-
38
- return $ this ->repositoryList [$ repositoryHash ] = $ this ->createRepository ($ entityManager , $ entityName );
30
+ return $ this ->repositoryList [$ repositoryHash ] ??= $ this ->createRepository ($ entityManager , $ entityName );
39
31
}
40
32
41
33
/**
@@ -47,22 +39,11 @@ public function getRepository(EntityManagerInterface $entityManager, $entityName
47
39
private function createRepository (
48
40
EntityManagerInterface $ entityManager ,
49
41
string $ entityName
50
- ): ObjectRepository {
42
+ ): EntityRepository {
51
43
$ metadata = $ entityManager ->getClassMetadata ($ entityName );
52
44
$ repositoryClassName = $ metadata ->customRepositoryClassName
53
45
?: $ entityManager ->getConfiguration ()->getDefaultRepositoryClassName ();
54
46
55
- $ repository = new $ repositoryClassName ($ entityManager , $ metadata );
56
- if (! $ repository instanceof EntityRepository) {
57
- Deprecation::trigger (
58
- 'doctrine/orm ' ,
59
- 'https://github.com/doctrine/orm/pull/9533 ' ,
60
- 'Configuring %s as repository class is deprecated because it does not extend %s. ' ,
61
- $ repositoryClassName ,
62
- EntityRepository::class
63
- );
64
- }
65
-
66
- return $ repository ;
47
+ return new $ repositoryClassName ($ entityManager , $ metadata );
67
48
}
68
49
}
0 commit comments