]> Raphaƫl G. Git Repositories - userbundle/blobdiff - Repository.php
Replace index translation by users
[userbundle] / Repository.php
index b21b0ca90f87819866419346f01b13533cf5b6c5..f6207e705401927fa42d4cd182e124a770b3be34 100644 (file)
@@ -14,17 +14,31 @@ namespace Rapsys\UserBundle;
 use Doctrine\ORM\EntityManagerInterface;
 use Doctrine\ORM\EntityRepository;
 use Doctrine\ORM\Mapping\ClassMetadata;
 use Doctrine\ORM\EntityManagerInterface;
 use Doctrine\ORM\EntityRepository;
 use Doctrine\ORM\Mapping\ClassMetadata;
-use Symfony\Component\Routing\RouterInterface;
-use Symfony\Contracts\Translation\TranslatorInterface;
+
+use Psr\Container\ContainerInterface;
 
 use Rapsys\PackBundle\Util\SluggerUtil;
 
 use Rapsys\PackBundle\Util\SluggerUtil;
+use Rapsys\UserBundle\RapsysUserBundle;
+
+use Symfony\Component\Routing\RouterInterface;
+use Symfony\Contracts\Translation\TranslatorInterface;
 
 /**
 
 /**
- * Repository
- *
  * {@inheritdoc}
  * {@inheritdoc}
+ *
+ * Repository
  */
 class Repository extends EntityRepository {
  */
 class Repository extends EntityRepository {
+       /**
+        * Alias string
+        */
+       protected string $alias;
+
+       /**
+        * Config array
+        */
+       protected array $config;
+
        /**
         * The table keys array
         *
        /**
         * The table keys array
         *
@@ -44,15 +58,20 @@ class Repository extends EntityRepository {
         *
         * @param EntityManagerInterface $manager The EntityManagerInterface instance
         * @param ClassMetadata $class The ClassMetadata instance
         *
         * @param EntityManagerInterface $manager The EntityManagerInterface instance
         * @param ClassMetadata $class The ClassMetadata instance
+        * @param ContainerInterface $container The container instance
         * @param RouterInterface $router The router instance
         * @param SluggerUtil $slugger The SluggerUtil instance
         * @param TranslatorInterface $translator The TranslatorInterface instance
         * @param string $locale The current locale
         */
         * @param RouterInterface $router The router instance
         * @param SluggerUtil $slugger The SluggerUtil instance
         * @param TranslatorInterface $translator The TranslatorInterface instance
         * @param string $locale The current locale
         */
-       public function __construct(protected EntityManagerInterface $manager, protected ClassMetadata $class, protected RouterInterface $router, protected SluggerUtil $slugger, protected TranslatorInterface $translator, protected string $locale) {
+       public function __construct(protected EntityManagerInterface $manager, protected ClassMetadata $class, protected ContainerInterface $container, protected RouterInterface $router, protected SluggerUtil $slugger, protected TranslatorInterface $translator, protected string $locale) {
                //Call parent constructor
                parent::__construct($manager, $class);
 
                //Call parent constructor
                parent::__construct($manager, $class);
 
+               //Get config
+               //XXX: extracting doctrine.orm.resolve_target_entities seems too complicated and doctrine listener is unusable to get reliable target entities resolution here
+               $this->config = $container->getParameter($this->alias = RapsysUserBundle::getAlias());
+
                //Get quote strategy
                $qs = $manager->getConfiguration()->getQuoteStrategy();
                $dp = $manager->getConnection()->getDatabasePlatform();
                //Get quote strategy
                $qs = $manager->getConfiguration()->getQuoteStrategy();
                $dp = $manager->getConnection()->getDatabasePlatform();
@@ -60,12 +79,13 @@ class Repository extends EntityRepository {
                //Set quoted table names
                //XXX: this allow to make this code table name independent
                //XXX: remember to place longer prefix before shorter to avoid strange replacings
                //Set quoted table names
                //XXX: this allow to make this code table name independent
                //XXX: remember to place longer prefix before shorter to avoid strange replacings
+               //XXX: entity short syntax removed in doctrine/persistence 3.x: https://github.com/doctrine/orm/issues/8818
                $tables = [
                        //Set entities
                $tables = [
                        //Set entities
-                       'RapsysUserBundle:UserGroup' => $qs->getJoinTableName($manager->getClassMetadata('Rapsys\UserBundle\Entity\User')->getAssociationMapping('groups'), $manager->getClassMetadata('Rapsys\UserBundle\Entity\User'), $dp),
-                       'RapsysUserBundle:Civility' => $qs->getTableName($manager->getClassMetadata('Rapsys\UserBundle\Entity\Civility'), $dp),
-                       'RapsysUserBundle:Group' => $qs->getTableName($manager->getClassMetadata('Rapsys\UserBundle\Entity\Group'), $dp),
-                       'RapsysUserBundle:User' => $qs->getTableName($manager->getClassMetadata('Rapsys\UserBundle\Entity\User'), $dp),
+                       'Rapsys\UserBundle\Entity\UserGroup' => $qs->getJoinTableName($manager->getClassMetadata($this->config['class']['user'])->getAssociationMapping('groups'), $manager->getClassMetadata($this->config['class']['user']), $dp),
+                       'Rapsys\UserBundle\Entity\Civility' => $qs->getTableName($manager->getClassMetadata($this->config['class']['civility']), $dp),
+                       'Rapsys\UserBundle\Entity\Group' => $qs->getTableName($manager->getClassMetadata($this->config['class']['group']), $dp),
+                       'Rapsys\UserBundle\Entity\User' => $qs->getTableName($manager->getClassMetadata($this->config['class']['user']), $dp),
                        //Set locale
                        //XXX: or $manager->getConnection()->quote($this->locale) ???
                        ':locale' => $dp->quoteStringLiteral($this->locale),
                        //Set locale
                        //XXX: or $manager->getConnection()->quote($this->locale) ???
                        ':locale' => $dp->quoteStringLiteral($this->locale),