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\SluggerUtil
; 
  22 use Symfony\Component\Routing\RouterInterface
; 
  23 use Symfony\Contracts\Translation\TranslatorInterface
; 
  30 class Repository 
extends EntityRepository 
{ 
  32          * The table keys array 
  36         protected array $keys; 
  39          * The table names array 
  43         protected array $names; 
  46          * Initializes a new LocationRepository instance 
  48          * @param EntityManagerInterface $manager The EntityManagerInterface instance 
  49          * @param ClassMetadata $class The ClassMetadata instance 
  50          * @param ContainerInterface $container The container instance 
  51          * @param RouterInterface $router The router instance 
  52          * @param SluggerUtil $slugger The SluggerUtil instance 
  53          * @param TranslatorInterface $translator The TranslatorInterface instance 
  54          * @param string $locale The current locale 
  55          * @param array $languages The languages list 
  57         public function __construct(protected EntityManagerInterface 
$manager, protected ClassMetadata 
$class, protected ContainerInterface 
$container, protected RouterInterface 
$router, protected SluggerUtil 
$slugger, protected TranslatorInterface 
$translator, protected string $locale, protected array $languages) { 
  58                 //Call parent constructor 
  59                 parent
::__construct($this->manager
, $this->class); 
  62                 $qs = $this->manager
->getConfiguration()->getQuoteStrategy(); 
  63                 $dp = $this->manager
->getConnection()->getDatabasePlatform(); 
  65                 //Set quoted table names 
  66                 //XXX: this allow to make this code table name independent 
  67                 //XXX: remember to place longer prefix before shorter to avoid strange replacings 
  68                 //XXX: entity short syntax removed in doctrine/persistence 3.x: https://github.com/doctrine/orm/issues/8818 
  70                         'Rapsys\TreeBundle\Entity\UserGroup' => $qs->getJoinTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\User')->getAssociationMapping('groups'), $manager->getClassMetadata('Rapsys\TreeBundle\Entity\User'), $dp), 
  71                         'Rapsys\TreeBundle\Entity\Album' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Album'), $dp), 
  72                         'Rapsys\TreeBundle\Entity\Civility' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Civility'), $dp), 
  73                         'Rapsys\TreeBundle\Entity\Element' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Element'), $dp), 
  74                         'Rapsys\TreeBundle\Entity\Group' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Group'), $dp), 
  75                         'Rapsys\TreeBundle\Entity\User' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\User'), $dp), 
  77                         //XXX: or $manager->getConnection()->quote($this->locale) ??? 
  78                         ':locale' => $dp->quoteStringLiteral($this->locale
), 
  80                         //XXX: Set limit used to workaround mariadb subselect optimization 
  81                         ':limit' => PHP_INT_MAX
, 
  88                 //Set quoted table keys 
  89                 $this->keys 
= array_keys($tables); 
  91                 //Set quoted table names 
  92                 $this->names 
= array_values($tables); 
  98          * @param string $req The request to replace 
  99          * @return string The replaced request 
 101         protected function replace(string $req): string { 
 102                 //Replace bundle entity name by table name 
 103                 return str_replace($this->keys
, $this->names
, $req);