* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Rapsys\TreeBundle; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Mapping\ClassMetadata; use Psr\Container\ContainerInterface; use Rapsys\PackBundle\Util\SluggerUtil; use Symfony\Component\Routing\RouterInterface; use Symfony\Contracts\Translation\TranslatorInterface; /** * Repository * * {@inheritdoc} */ class Repository extends EntityRepository { /** * The table keys array * * @var array */ protected array $keys; /** * The table names array * * @var array */ protected array $names; /** * Initializes a new LocationRepository 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 array $languages The languages list */ 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) { //Call parent constructor parent::__construct($this->manager, $this->class); //Get quote strategy $qs = $this->manager->getConfiguration()->getQuoteStrategy(); $dp = $this->manager->getConnection()->getDatabasePlatform(); //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 = [ 'Rapsys\TreeBundle\Entity\UserGroup' => $qs->getJoinTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\User')->getAssociationMapping('groups'), $manager->getClassMetadata('Rapsys\TreeBundle\Entity\User'), $dp), 'Rapsys\TreeBundle\Entity\Album' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Album'), $dp), 'Rapsys\TreeBundle\Entity\Civility' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Civility'), $dp), 'Rapsys\TreeBundle\Entity\Element' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Element'), $dp), 'Rapsys\TreeBundle\Entity\Group' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Group'), $dp), 'Rapsys\TreeBundle\Entity\User' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\User'), $dp), //Set locale //XXX: or $manager->getConnection()->quote($this->locale) ??? ':locale' => $dp->quoteStringLiteral($this->locale), //Set limit //XXX: Set limit used to workaround mariadb subselect optimization ':limit' => PHP_INT_MAX, //Set cleanup "\t" => '', "\r" => ' ', "\n" => ' ' ]; //Set quoted table keys $this->keys = array_keys($tables); //Set quoted table names $this->names = array_values($tables); } /** * Get replaced query * * @param string $req The request to replace * @return string The replaced request */ protected function replace(string $req): string { //Replace bundle entity name by table name return str_replace($this->keys, $this->names, $req); } }