]> Raphaël G. Git Repositories - userbundle/blob - Repository.php
Fix confirm route user controller method
[userbundle] / Repository.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys UserBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\UserBundle;
13
14 use Doctrine\ORM\EntityManagerInterface;
15 use Doctrine\ORM\EntityRepository;
16 use Doctrine\ORM\Mapping\ClassMetadata;
17
18 use Rapsys\PackBundle\Util\SluggerUtil;
19
20 use Symfony\Component\Routing\RouterInterface;
21 use Symfony\Contracts\Translation\TranslatorInterface;
22
23 /**
24 * {@inheritdoc}
25 *
26 * Repository
27 */
28 class Repository extends EntityRepository {
29 /**
30 * The table keys array
31 *
32 * @var array
33 */
34 protected array $tableKeys;
35
36 /**
37 * The table values array
38 *
39 * @var array
40 */
41 protected array $tableValues;
42
43 /**
44 * Initializes a new LocationRepository instance
45 *
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
52 */
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);
56
57 //Get quote strategy
58 $qs = $manager->getConfiguration()->getQuoteStrategy();
59 $dp = $manager->getConnection()->getDatabasePlatform();
60
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
64 $tables = [
65 //Set entities
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),
70 //Set locale
71 //XXX: or $manager->getConnection()->quote($this->locale) ???
72 ':locale' => $dp->quoteStringLiteral($this->locale),
73 //Set limit
74 //XXX: Set limit used to workaround mariadb subselect optimization
75 ':limit' => PHP_INT_MAX,
76 //Set cleanup
77 "\t" => '',
78 "\r" => ' ',
79 "\n" => ' '
80 ];
81
82 //Set quoted table name keys
83 $this->tableKeys = array_keys($tables);
84
85 //Set quoted table name values
86 $this->tableValues = array_values($tables);
87 }
88
89 /**
90 * Get replaced query
91 *
92 * @param string $req The request to replace
93 * @return string The replaced request
94 */
95 protected function replace(string $req): string {
96 //Replace bundle entity name by table name
97 return str_replace($this->tableKeys, $this->tableValues, $req);
98 }
99 }