mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-09 16:53:11 +08:00
Remove dependencies on url_shortener raw config
This commit is contained in:
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Config\PostProcessor;
|
||||
|
||||
use Shlinkio\Shlink\Core\Config\EnvVars;
|
||||
|
||||
use function array_map;
|
||||
use function str_replace;
|
||||
|
||||
@@ -14,7 +16,7 @@ class MultiSegmentSlugProcessor
|
||||
|
||||
public function __invoke(array $config): array
|
||||
{
|
||||
$multiSegmentEnabled = $config['url_shortener']['multi_segment_slugs_enabled'] ?? false;
|
||||
$multiSegmentEnabled = (bool) EnvVars::MULTI_SEGMENT_SLUGS_ENABLED->loadFromEnv();
|
||||
if (! $multiSegmentEnabled) {
|
||||
return $config;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -5,22 +5,23 @@ declare(strict_types=1);
|
||||
namespace Shlinkio\Shlink\Core\ShortUrl\Helper;
|
||||
|
||||
use Laminas\Diactoros\Uri;
|
||||
use Shlinkio\Shlink\Core\Config\Options\UrlShortenerOptions;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||
|
||||
use function sprintf;
|
||||
|
||||
class ShortUrlStringifier implements ShortUrlStringifierInterface
|
||||
readonly class ShortUrlStringifier implements ShortUrlStringifierInterface
|
||||
{
|
||||
/**
|
||||
* @param array{schema?: string, hostname?: string} $domainConfig
|
||||
*/
|
||||
public function __construct(private readonly array $domainConfig, private readonly string $basePath = '')
|
||||
{
|
||||
public function __construct(
|
||||
private UrlShortenerOptions $urlShortenerOptions = new UrlShortenerOptions(),
|
||||
private string $basePath = '',
|
||||
) {
|
||||
}
|
||||
|
||||
public function stringify(ShortUrl $shortUrl): string
|
||||
{
|
||||
$uriWithoutShortCode = (new Uri())->withScheme($this->domainConfig['schema'] ?? 'http')
|
||||
$domainConfig = $this->urlShortenerOptions->domain;
|
||||
$uriWithoutShortCode = (new Uri())->withScheme($domainConfig['schema'] ?? 'http')
|
||||
->withHost($this->resolveDomain($shortUrl))
|
||||
->withPath($this->basePath)
|
||||
->__toString();
|
||||
@@ -31,6 +32,7 @@ class ShortUrlStringifier implements ShortUrlStringifierInterface
|
||||
|
||||
private function resolveDomain(ShortUrl $shortUrl): string
|
||||
{
|
||||
return $shortUrl->getDomain()?->authority ?? $this->domainConfig['hostname'] ?? '';
|
||||
$domainConfig = $this->urlShortenerOptions->domain;
|
||||
return $shortUrl->getDomain()?->authority ?? $domainConfig['hostname'] ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user