10
10
use Creative \DbI18nBundle \Interfaces \DbLoaderInterface ;
11
11
use Creative \DbI18nBundle \Interfaces \EntityInterface ;
12
12
use Creative \DbI18nBundle \Interfaces \TranslationRepositoryInterface ;
13
- use Doctrine \Common \Persistence \ObjectRepository ;
14
- use Doctrine \ORM \EntityManagerInterface ;
13
+ use Doctrine \Persistence \ManagerRegistry ;
15
14
use Symfony \Component \DependencyInjection \ContainerInterface ;
16
15
use Symfony \Component \Translation \Exception \InvalidResourceException ;
17
16
use Symfony \Component \Translation \Exception \NotFoundResourceException ;
25
24
class DbLoader implements LoaderInterface, DbLoaderInterface
26
25
{
27
26
/**
28
- * @var EntityManagerInterface
27
+ * @var ManagerRegistry
29
28
*/
30
29
private $ doctrine ;
31
30
@@ -37,9 +36,9 @@ class DbLoader implements LoaderInterface, DbLoaderInterface
37
36
/**
38
37
* DbLoader constructor.
39
38
* @param ContainerInterface $container
40
- * @param EntityManagerInterface $doctrine
39
+ * @param ManagerRegistry $doctrine
41
40
*/
42
- public function __construct (ContainerInterface $ container , EntityManagerInterface $ doctrine )
41
+ public function __construct (ContainerInterface $ container , ManagerRegistry $ doctrine )
43
42
{
44
43
$ this ->doctrine = $ doctrine ;
45
44
$ this ->entityClass = $ container ->getParameter ('db_i18n.entity ' );
@@ -73,10 +72,15 @@ public function load($resource, $locale, $domain = 'messages')
73
72
}
74
73
75
74
/**
76
- * @return TranslationRepositoryInterface|ObjectRepository
75
+ * {@inheritDoc}
77
76
*/
78
77
public function getRepository (): TranslationRepositoryInterface
79
78
{
80
- return $ this ->doctrine ->getRepository ($ this ->entityClass );
79
+ $ repository = $ this ->doctrine ->getRepository ($ this ->entityClass );
80
+ if ($ repository instanceof TranslationRepositoryInterface) {
81
+ return $ repository ;
82
+ }
83
+
84
+ throw new \RuntimeException (\sprintf ('Cannot load repository %s ' , TranslationRepositoryInterface::class));
81
85
}
82
86
}
0 commit comments