Remove dependencies on url_shortener raw config

This commit is contained in:
Alejandro Celaya
2024-10-20 12:52:00 +02:00
parent b991b1699e
commit c8e5196aab
26 changed files with 83 additions and 84 deletions

View File

@@ -7,6 +7,7 @@ namespace Shlinkio\Shlink\Core\Domain;
use Doctrine\ORM\EntityManagerInterface;
use Shlinkio\Shlink\Core\Config\EmptyNotFoundRedirectConfig;
use Shlinkio\Shlink\Core\Config\NotFoundRedirects;
use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions;
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
use Shlinkio\Shlink\Core\Domain\Model\DomainItem;
use Shlinkio\Shlink\Core\Domain\Repository\DomainRepositoryInterface;
@@ -16,9 +17,9 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey;
use function array_map;
class DomainService implements DomainServiceInterface
readonly class DomainService implements DomainServiceInterface
{
public function __construct(private readonly EntityManagerInterface $em, private readonly string $defaultDomain)
public function __construct(private EntityManagerInterface $em, private UrlShortenerOptions $urlShortenerOptions)
{
}
@@ -35,7 +36,10 @@ class DomainService implements DomainServiceInterface
}
return [
DomainItem::forDefaultDomain($this->defaultDomain, $default ?? new EmptyNotFoundRedirectConfig()),
DomainItem::forDefaultDomain(
$this->urlShortenerOptions->defaultDomain(),
$default ?? new EmptyNotFoundRedirectConfig(),
),
...$mappedDomains,
];
}
@@ -52,7 +56,7 @@ class DomainService implements DomainServiceInterface
$restOfDomains = [];
foreach ($allDomains as $domain) {
if ($domain->authority === $this->defaultDomain) {
if ($domain->authority === $this->urlShortenerOptions->defaultDomain()) {
$defaultDomain = $domain;
} else {
$restOfDomains[] = $domain;