2026-05-18 07:53:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Infrastructure\Persistence\Repository;
|
|
|
|
|
|
|
|
|
|
use App\Domain\I18n\Repository\TranslationRepositoryInterface;
|
|
|
|
|
use App\Domain\I18n\Translation;
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
|
|
|
|
|
|
final class DoctrineTranslationRepository implements TranslationRepositoryInterface
|
|
|
|
|
{
|
2026-05-19 10:56:37 +00:00
|
|
|
public function __construct(private readonly EntityManagerInterface $em)
|
|
|
|
|
{
|
|
|
|
|
}
|
2026-05-18 07:53:52 +00:00
|
|
|
|
|
|
|
|
public function findMapByLocaleAndDomain(string $locale, string $domain): array
|
|
|
|
|
{
|
|
|
|
|
$rows = $this->em->createQuery(
|
|
|
|
|
'SELECT t.key, t.value FROM App\Domain\I18n\Translation t
|
|
|
|
|
WHERE t.locale = :locale AND t.domain = :domain'
|
|
|
|
|
)
|
|
|
|
|
->setParameter('locale', $locale)
|
|
|
|
|
->setParameter('domain', $domain)
|
|
|
|
|
->getArrayResult();
|
|
|
|
|
|
|
|
|
|
$map = [];
|
|
|
|
|
foreach ($rows as $row) {
|
|
|
|
|
$map[$row['key']] = $row['value'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function findAll(): array
|
|
|
|
|
{
|
|
|
|
|
return $this->em->createQuery(
|
|
|
|
|
'SELECT t FROM App\Domain\I18n\Translation t ORDER BY t.domain ASC, t.locale ASC, t.key ASC'
|
|
|
|
|
)->getResult();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function save(Translation $translation): void
|
|
|
|
|
{
|
|
|
|
|
$this->em->persist($translation);
|
|
|
|
|
$this->em->flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function remove(Translation $translation): void
|
|
|
|
|
{
|
|
|
|
|
$this->em->remove($translation);
|
|
|
|
|
$this->em->flush();
|
|
|
|
|
}
|
|
|
|
|
}
|