Inject DomainRepository in DomainService

This commit is contained in:
Alejandro Celaya
2024-11-09 09:34:24 +01:00
parent dba9302f78
commit 102169b6c7
3 changed files with 27 additions and 22 deletions

View File

@@ -19,8 +19,11 @@ use function array_map;
readonly class DomainService implements DomainServiceInterface
{
public function __construct(private EntityManagerInterface $em, private UrlShortenerOptions $urlShortenerOptions)
{
public function __construct(
private EntityManagerInterface $em,
private UrlShortenerOptions $urlShortenerOptions,
private DomainRepositoryInterface $repo,
) {
}
/**
@@ -49,9 +52,7 @@ readonly class DomainService implements DomainServiceInterface
*/
private function defaultDomainAndRest(ApiKey|null $apiKey): array
{
/** @var DomainRepositoryInterface $repo */
$repo = $this->em->getRepository(Domain::class);
$allDomains = $repo->findDomains($apiKey);
$allDomains = $this->repo->findDomains($apiKey);
$defaultDomain = null;
$restOfDomains = [];
@@ -71,7 +72,6 @@ readonly class DomainService implements DomainServiceInterface
*/
public function getDomain(string $domainId): Domain
{
/** @var Domain|null $domain */
$domain = $this->em->find(Domain::class, $domainId);
if ($domain === null) {
throw DomainNotFoundException::fromId($domainId);
@@ -82,7 +82,7 @@ readonly class DomainService implements DomainServiceInterface
public function findByAuthority(string $authority, ApiKey|null $apiKey = null): Domain|null
{
return $this->em->getRepository(Domain::class)->findOneByAuthority($authority, $apiKey);
return $this->repo->findOneByAuthority($authority, $apiKey);
}
/**