mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 01:33:11 +08:00
Refactored short URL creation so that the long URL is part of the ShortUrlMeta
This commit is contained in:
@@ -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[]
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user