1 <?php 
declare(strict_types
=1); 
   4  * This file is part of the Rapsys TreeBundle 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\TreeBundle
; 
  14 use Doctrine\ORM\EntityManagerInterface
; 
  15 use Doctrine\ORM\EntityRepository
; 
  16 use Doctrine\ORM\Mapping\ClassMetadata
; 
  18 use Psr\Container\ContainerInterface
; 
  20 use Rapsys\PackBundle\Util\FileUtil
; 
  21 use Rapsys\PackBundle\Util\SluggerUtil
; 
  23 use Symfony\Component\Routing\RouterInterface
; 
  24 use Symfony\Contracts\Translation\TranslatorInterface
; 
  31 class Repository 
extends EntityRepository 
{ 
  33          * The table keys array 
  37         protected array $keys; 
  40          * The table names array 
  44         protected array $names; 
  47          * Initializes a new LocationRepository instance 
  49          * @param EntityManagerInterface $manager The EntityManagerInterface instance 
  50          * @param ClassMetadata $class The ClassMetadata instance 
  51          * @param ContainerInterface $container The container instance 
  52          * @param FileUtil $file The FileUtil instance 
  53          * @param RouterInterface $router The router instance 
  54          * @param SluggerUtil $slugger The SluggerUtil instance 
  55          * @param TranslatorInterface $translator The TranslatorInterface instance 
  56          * @param string $locale The current locale 
  57          * @param array $languages The languages list 
  59         public function __construct(protected EntityManagerInterface 
$manager, protected ClassMetadata 
$class, protected ContainerInterface 
$container, protected FileUtil 
$file, protected RouterInterface 
$router, protected SluggerUtil 
$slugger, protected TranslatorInterface 
$translator, protected string $locale, protected array $languages) { 
  60                 //Call parent constructor 
  61                 parent
::__construct($this->manager
, $this->class); 
  64                 $qs = $this->manager
->getConfiguration()->getQuoteStrategy(); 
  65                 $dp = $this->manager
->getConnection()->getDatabasePlatform(); 
  67                 //Set quoted table names 
  68                 //XXX: this allow to make this code table name independent 
  69                 //XXX: remember to place longer prefix before shorter to avoid strange replacings 
  70                 //XXX: entity short syntax removed in doctrine/persistence 3.x: https://github.com/doctrine/orm/issues/8818 
  72                         'Rapsys\TreeBundle\Entity\UserGroup' => $qs->getJoinTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\User')->getAssociationMapping('groups'), $manager->getClassMetadata('Rapsys\TreeBundle\Entity\User'), $dp), 
  73                         'Rapsys\TreeBundle\Entity\Album' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Album'), $dp), 
  74                         'Rapsys\TreeBundle\Entity\Civility' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Civility'), $dp), 
  75                         'Rapsys\TreeBundle\Entity\Element' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Element'), $dp), 
  76                         'Rapsys\TreeBundle\Entity\Group' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Group'), $dp), 
  77                         'Rapsys\TreeBundle\Entity\User' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\User'), $dp), 
  79                         //XXX: or $manager->getConnection()->quote($this->locale) ??? 
  80                         ':locale' => $dp->quoteStringLiteral($this->locale
), 
  82                         //XXX: Set limit used to workaround mariadb subselect optimization 
  83                         ':limit' => PHP_INT_MAX
, 
  90                 //Set quoted table keys 
  91                 $this->keys 
= array_keys($tables); 
  93                 //Set quoted table names 
  94                 $this->names 
= array_values($tables); 
 100          * @param string $req The request to replace 
 101          * @return string The replaced request 
 103         protected function replace(string $req): string { 
 104                 //Replace bundle entity name by table name 
 105                 return str_replace($this->keys
, $this->names
, $req);