1010use Creative \DbI18nBundle \Interfaces \DbLoaderInterface ;
1111use Creative \DbI18nBundle \Interfaces \EntityInterface ;
1212use Creative \DbI18nBundle \Interfaces \TranslationRepositoryInterface ;
13- use Doctrine \Common \Persistence \ObjectRepository ;
14- use Doctrine \ORM \EntityManagerInterface ;
13+ use Doctrine \Persistence \ManagerRegistry ;
1514use Symfony \Component \DependencyInjection \ContainerInterface ;
1615use Symfony \Component \Translation \Exception \InvalidResourceException ;
1716use Symfony \Component \Translation \Exception \NotFoundResourceException ;
2524class DbLoader implements LoaderInterface, DbLoaderInterface
2625{
2726 /**
28- * @var EntityManagerInterface
27+ * @var ManagerRegistry
2928 */
3029 private $ doctrine ;
3130
@@ -37,9 +36,9 @@ class DbLoader implements LoaderInterface, DbLoaderInterface
3736 /**
3837 * DbLoader constructor.
3938 * @param ContainerInterface $container
40- * @param EntityManagerInterface $doctrine
39+ * @param ManagerRegistry $doctrine
4140 */
42- public function __construct (ContainerInterface $ container , EntityManagerInterface $ doctrine )
41+ public function __construct (ContainerInterface $ container , ManagerRegistry $ doctrine )
4342 {
4443 $ this ->doctrine = $ doctrine ;
4544 $ this ->entityClass = $ container ->getParameter ('db_i18n.entity ' );
@@ -73,10 +72,15 @@ public function load($resource, $locale, $domain = 'messages')
7372 }
7473
7574 /**
76- * @return TranslationRepositoryInterface|ObjectRepository
75+ * {@inheritDoc}
7776 */
7877 public function getRepository (): TranslationRepositoryInterface
7978 {
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));
8185 }
8286}
0 commit comments