mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-10 17:23:12 +08:00
Inject DomainRepository in DomainService
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user