Added support for an optional title field in short URLs

This commit is contained in:
Alejandro Celaya
2021-02-02 20:21:48 +01:00
parent 31a7212a71
commit 430c407106
8 changed files with 71 additions and 7 deletions

View File

@@ -28,6 +28,7 @@ final class ShortUrlMeta
private ?bool $validateUrl = null;
private ?ApiKey $apiKey = null;
private array $tags = [];
private ?string $title = null;
private function __construct()
{
@@ -76,6 +77,7 @@ final class ShortUrlMeta
) ?? DEFAULT_SHORT_CODES_LENGTH;
$this->apiKey = $inputFilter->getValue(ShortUrlInputFilter::API_KEY);
$this->tags = $inputFilter->getValue(ShortUrlInputFilter::TAGS);
$this->title = $inputFilter->getValue(ShortUrlInputFilter::TITLE);
}
public function getLongUrl(): string
@@ -160,4 +162,9 @@ final class ShortUrlMeta
{
return $this->tags;
}
public function getTitle(): ?string
{
return $this->title;
}
}

View File

@@ -6,6 +6,7 @@ namespace Shlinkio\Shlink\Core\Model;
use Shlinkio\Shlink\Core\Exception\ValidationException;
use function array_pad;
use function explode;
use function is_array;
use function is_string;
@@ -50,9 +51,9 @@ final class ShortUrlsOrdering
/** @var string|array $orderBy */
if (! $isArray) {
$parts = explode('-', $orderBy);
$this->orderField = $parts[0];
$this->orderDirection = $parts[1] ?? self::DEFAULT_ORDER_DIRECTION;
[$field, $dir] = array_pad(explode('-', $orderBy), 2, null);
$this->orderField = $field;
$this->orderDirection = $dir ?? self::DEFAULT_ORDER_DIRECTION;
} else {
$this->orderField = key($orderBy);
$this->orderDirection = $orderBy[$this->orderField];