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
;
18 use Rapsys\PackBundle\Util\SluggerUtil
;
20 use Symfony\Component\Routing\RouterInterface
;
21 use Symfony\Contracts\Translation\TranslatorInterface
;
28 class Repository
extends EntityRepository
{
30 * The table keys array
34 protected array $tableKeys;
37 * The table values array
41 protected array $tableValues;
44 * Initializes a new LocationRepository instance
46 * @param EntityManagerInterface $manager The EntityManagerInterface instance
47 * @param ClassMetadata $class The ClassMetadata instance
48 * @param RouterInterface $router The router instance
49 * @param SluggerUtil $slugger The SluggerUtil instance
50 * @param TranslatorInterface $translator The TranslatorInterface instance
51 * @param string $locale The current locale
53 public function __construct(protected EntityManagerInterface
$manager, protected ClassMetadata
$class, protected RouterInterface
$router, protected SluggerUtil
$slugger, protected TranslatorInterface
$translator, protected string $locale) {
54 //Call parent constructor
55 parent
::__construct($manager, $class);
58 $qs = $manager->getConfiguration()->getQuoteStrategy();
59 $dp = $manager->getConnection()->getDatabasePlatform();
61 //Set quoted table names
62 //XXX: this allow to make this code table name independent
63 //XXX: remember to place longer prefix before shorter to avoid strange replacings
66 'RapsysUserBundle:UserGroup' => $qs->getJoinTableName($manager->getClassMetadata('Rapsys\UserBundle\Entity\User')->getAssociationMapping('groups'), $manager->getClassMetadata('Rapsys\UserBundle\Entity\User'), $dp),
67 'RapsysUserBundle:Civility' => $qs->getTableName($manager->getClassMetadata('Rapsys\UserBundle\Entity\Civility'), $dp),
68 'RapsysUserBundle:Group' => $qs->getTableName($manager->getClassMetadata('Rapsys\UserBundle\Entity\Group'), $dp),
69 'RapsysUserBundle:User' => $qs->getTableName($manager->getClassMetadata('Rapsys\UserBundle\Entity\User'), $dp),
71 //XXX: or $manager->getConnection()->quote($this->locale) ???
72 ':locale' => $dp->quoteStringLiteral($this->locale
),
74 //XXX: Set limit used to workaround mariadb subselect optimization
75 ':limit' => PHP_INT_MAX
,
82 //Set quoted table name keys
83 $this->tableKeys
= array_keys($tables);
85 //Set quoted table name values
86 $this->tableValues
= array_values($tables);
92 * @param string $req The request to replace
93 * @return string The replaced request
95 protected function replace(string $req): string {
96 //Replace bundle entity name by table name
97 return str_replace($this->tableKeys
, $this->tableValues
, $req);