1 <?php 
declare(strict_types
=1); 
   4  * This file is part of the Rapsys UserBundle package. 
   6  * (c) Raphaël Gertz <symfony@rapsys.eu> 
   8  * For the full copyright and license information, please view the LICENSE 
   9  * file that was distributed with this source code. 
  12 namespace Rapsys\UserBundle
; 
  14 use Doctrine\ORM\EntityManagerInterface
; 
  15 use Doctrine\ORM\EntityRepository
; 
  16 use Doctrine\ORM\Mapping\ClassMetadata
; 
  17 use Symfony\Component\Routing\RouterInterface
; 
  18 use Symfony\Contracts\Translation\TranslatorInterface
; 
  20 use Rapsys\PackBundle\Util\SluggerUtil
; 
  27 class Repository 
extends EntityRepository 
{ 
  29          * The table keys array 
  33         protected array $tableKeys; 
  36          * The table values array 
  40         protected array $tableValues; 
  43          * Initializes a new LocationRepository instance 
  45          * @param EntityManagerInterface $manager The EntityManagerInterface instance 
  46          * @param ClassMetadata $class The ClassMetadata instance 
  47          * @param RouterInterface $router The router instance 
  48          * @param SluggerUtil $slugger The SluggerUtil instance 
  49          * @param TranslatorInterface $translator The TranslatorInterface instance 
  50          * @param string $locale The current locale 
  52         public function __construct(protected EntityManagerInterface 
$manager, protected ClassMetadata 
$class, protected RouterInterface 
$router, protected SluggerUtil 
$slugger, protected TranslatorInterface 
$translator, protected string $locale) { 
  53                 //Call parent constructor 
  54                 parent
::__construct($manager, $class); 
  57                 $qs = $manager->getConfiguration()->getQuoteStrategy(); 
  58                 $dp = $manager->getConnection()->getDatabasePlatform(); 
  60                 //Set quoted table names 
  61                 //XXX: this allow to make this code table name independent 
  62                 //XXX: remember to place longer prefix before shorter to avoid strange replacings 
  65                         'RapsysUserBundle:UserGroup' => $qs->getJoinTableName($manager->getClassMetadata('Rapsys\UserBundle\Entity\User')->getAssociationMapping('groups'), $manager->getClassMetadata('Rapsys\UserBundle\Entity\User'), $dp), 
  66                         'RapsysUserBundle:Civility' => $qs->getTableName($manager->getClassMetadata('Rapsys\UserBundle\Entity\Civility'), $dp), 
  67                         'RapsysUserBundle:Group' => $qs->getTableName($manager->getClassMetadata('Rapsys\UserBundle\Entity\Group'), $dp), 
  68                         'RapsysUserBundle:User' => $qs->getTableName($manager->getClassMetadata('Rapsys\UserBundle\Entity\User'), $dp), 
  70                         //XXX: or $manager->getConnection()->quote($this->locale) ??? 
  71                         ':locale' => $dp->quoteStringLiteral($this->locale
), 
  73                         //XXX: Set limit used to workaround mariadb subselect optimization 
  74                         ':limit' => PHP_INT_MAX
, 
  81                 //Set quoted table name keys 
  82                 $this->tableKeys 
= array_keys($tables); 
  84                 //Set quoted table name values 
  85                 $this->tableValues 
= array_values($tables); 
  91          * @param string $req The request to replace 
  92          * @return string The replaced request 
  94         protected function replace(string $req): string { 
  95                 //Replace bundle entity name by table name 
  96                 return str_replace($this->tableKeys
, $this->tableValues
, $req);