mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 23:33:13 +08:00
Moved TagsMode to its own enum
This commit is contained in:
@@ -6,6 +6,7 @@ namespace Shlinkio\Shlink\Core\Model;
|
||||
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
use Shlinkio\Shlink\Core\Exception\ValidationException;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Model\TagsMode;
|
||||
use Shlinkio\Shlink\Core\Validation\ShortUrlsParamsInputFilter;
|
||||
|
||||
use function Shlinkio\Shlink\Common\buildDateRange;
|
||||
@@ -16,16 +17,11 @@ final class ShortUrlsParams
|
||||
public const ORDERABLE_FIELDS = ['longUrl', 'shortCode', 'dateCreated', 'title', 'visits'];
|
||||
public const DEFAULT_ITEMS_PER_PAGE = 10;
|
||||
|
||||
// TODO Convert to enum
|
||||
public const TAGS_MODE_ANY = 'any';
|
||||
public const TAGS_MODE_ALL = 'all';
|
||||
|
||||
private int $page;
|
||||
private int $itemsPerPage;
|
||||
private ?string $searchTerm;
|
||||
private array $tags;
|
||||
/** @var self::TAGS_MODE_ANY|self::TAGS_MODE_ALL */
|
||||
private string $tagsMode = self::TAGS_MODE_ANY;
|
||||
private TagsMode $tagsMode = TagsMode::ANY;
|
||||
private Ordering $orderBy;
|
||||
private ?DateRange $dateRange;
|
||||
|
||||
@@ -70,7 +66,16 @@ final class ShortUrlsParams
|
||||
$this->itemsPerPage = (int) (
|
||||
$inputFilter->getValue(ShortUrlsParamsInputFilter::ITEMS_PER_PAGE) ?? self::DEFAULT_ITEMS_PER_PAGE
|
||||
);
|
||||
$this->tagsMode = $inputFilter->getValue(ShortUrlsParamsInputFilter::TAGS_MODE) ?? self::TAGS_MODE_ANY;
|
||||
$this->tagsMode = $this->resolveTagsMode($inputFilter->getValue(ShortUrlsParamsInputFilter::TAGS_MODE));
|
||||
}
|
||||
|
||||
private function resolveTagsMode(?string $rawTagsMode): TagsMode
|
||||
{
|
||||
if ($rawTagsMode === null) {
|
||||
return TagsMode::ANY;
|
||||
}
|
||||
|
||||
return TagsMode::tryFrom($rawTagsMode) ?? TagsMode::ANY;
|
||||
}
|
||||
|
||||
public function page(): int
|
||||
@@ -103,10 +108,7 @@ final class ShortUrlsParams
|
||||
return $this->dateRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return self::TAGS_MODE_ANY|self::TAGS_MODE_ALL
|
||||
*/
|
||||
public function tagsMode(): string
|
||||
public function tagsMode(): TagsMode
|
||||
{
|
||||
return $this->tagsMode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user