mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 17:44:44 +08:00
Allowed to resolve title during short URL edition if it has to
This commit is contained in:
@@ -61,8 +61,8 @@ class ShortUrlService implements ShortUrlServiceInterface
|
||||
ShortUrlEdit $shortUrlEdit,
|
||||
?ApiKey $apiKey = null
|
||||
): ShortUrl {
|
||||
if ($shortUrlEdit->hasLongUrl()) {
|
||||
$this->urlValidator->validateUrl($shortUrlEdit->longUrl(), $shortUrlEdit->doValidateUrl());
|
||||
if ($shortUrlEdit->longUrlWasProvided()) {
|
||||
$shortUrlEdit = $this->processTitleAndValidateUrl($shortUrlEdit);
|
||||
}
|
||||
|
||||
$shortUrl = $this->urlResolver->resolveShortUrl($identifier, $apiKey);
|
||||
@@ -72,4 +72,15 @@ class ShortUrlService implements ShortUrlServiceInterface
|
||||
|
||||
return $shortUrl;
|
||||
}
|
||||
|
||||
private function processTitleAndValidateUrl(ShortUrlEdit $shortUrlEdit): ShortUrlEdit
|
||||
{
|
||||
if ($shortUrlEdit->titleWasProvided()) {
|
||||
$this->urlValidator->validateUrl($shortUrlEdit->longUrl(), $shortUrlEdit->doValidateUrl());
|
||||
return $shortUrlEdit;
|
||||
}
|
||||
|
||||
$title = $this->urlValidator->validateUrlWithTitle($shortUrlEdit->longUrl(), $shortUrlEdit->doValidateUrl());
|
||||
return $title === null ? $shortUrlEdit : $shortUrlEdit->withResolvedTitle($title);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user