Refactored short URL creation so that the long URL is part of the ShortUrlMeta

This commit is contained in:
Alejandro Celaya
2021-01-30 14:18:44 +01:00
parent 56a2253535
commit 07b12fac3c
45 changed files with 343 additions and 306 deletions

View File

@@ -6,22 +6,15 @@ namespace Shlinkio\Shlink\Core\Model;
final class CreateShortUrlData
{
private string $longUrl;
private array $tags;
private ShortUrlMeta $meta;
public function __construct(string $longUrl, array $tags = [], ?ShortUrlMeta $meta = null)
public function __construct(array $tags = [], ?ShortUrlMeta $meta = null)
{
$this->longUrl = $longUrl;
$this->tags = $tags;
$this->meta = $meta ?? ShortUrlMeta::createEmpty();
}
public function getLongUrl(): string
{
return $this->longUrl;
}
/**
* @return string[]
*/

View File

@@ -17,6 +17,7 @@ use const Shlinkio\Shlink\Core\DEFAULT_SHORT_CODES_LENGTH;
final class ShortUrlMeta
{
private string $longUrl;
private ?Chronos $validSince = null;
private ?Chronos $validUntil = null;
private ?string $customSlug = null;
@@ -34,7 +35,10 @@ final class ShortUrlMeta
public static function createEmpty(): self
{
return new self();
$meta = new self();
$meta->longUrl = '';
return $meta;
}
/**
@@ -52,11 +56,12 @@ final class ShortUrlMeta
*/
private function validateAndInit(array $data): void
{
$inputFilter = new ShortUrlMetaInputFilter($data);
$inputFilter = new ShortUrlMetaInputFilter($data, true);
if (! $inputFilter->isValid()) {
throw ValidationException::fromInputFilter($inputFilter);
}
$this->longUrl = $inputFilter->getValue(ShortUrlMetaInputFilter::LONG_URL);
$this->validSince = parseDateField($inputFilter->getValue(ShortUrlMetaInputFilter::VALID_SINCE));
$this->validUntil = parseDateField($inputFilter->getValue(ShortUrlMetaInputFilter::VALID_UNTIL));
$this->customSlug = $inputFilter->getValue(ShortUrlMetaInputFilter::CUSTOM_SLUG);
@@ -71,6 +76,11 @@ final class ShortUrlMeta
$this->apiKey = $inputFilter->getValue(ShortUrlMetaInputFilter::API_KEY);
}
public function getLongUrl(): string
{
return $this->longUrl;
}
public function getValidSince(): ?Chronos
{
return $this->validSince;