mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 09:43:13 +08:00
Allow type filter property for orphan visits list
This commit is contained in:
53
module/Core/src/Visit/Model/OrphanVisitsParams.php
Normal file
53
module/Core/src/Visit/Model/OrphanVisitsParams.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Visit\Model;
|
||||
|
||||
use Shlinkio\Shlink\Common\Util\DateRange;
|
||||
use Shlinkio\Shlink\Core\Exception\ValidationException;
|
||||
use ValueError;
|
||||
|
||||
use function implode;
|
||||
use function Shlinkio\Shlink\Core\enumValues;
|
||||
use function sprintf;
|
||||
|
||||
final class OrphanVisitsParams extends VisitsParams
|
||||
{
|
||||
public function __construct(
|
||||
?DateRange $dateRange = null,
|
||||
?int $page = null,
|
||||
?int $itemsPerPage = null,
|
||||
bool $excludeBots = false,
|
||||
public readonly ?OrphanVisitType $type = null,
|
||||
) {
|
||||
parent::__construct($dateRange, $page, $itemsPerPage, $excludeBots);
|
||||
}
|
||||
|
||||
public static function fromRawData(array $query): self
|
||||
{
|
||||
$visitsParams = parent::fromRawData($query);
|
||||
$type = $query['type'] ?? null;
|
||||
|
||||
return new self(
|
||||
dateRange: $visitsParams->dateRange,
|
||||
page: $visitsParams->page,
|
||||
itemsPerPage: $visitsParams->itemsPerPage,
|
||||
excludeBots: $visitsParams->excludeBots,
|
||||
type: $type !== null ? self::parseType($type) : null,
|
||||
);
|
||||
}
|
||||
|
||||
private static function parseType(string $type): OrphanVisitType
|
||||
{
|
||||
try {
|
||||
return OrphanVisitType::from($type);
|
||||
} catch (ValueError) {
|
||||
throw ValidationException::fromArray([
|
||||
'type' => sprintf(
|
||||
'%s is not a valid orphan visit type. Expected one of ["%s"]',
|
||||
$type,
|
||||
implode('", "', enumValues(OrphanVisitType::class)),
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ use Shlinkio\Shlink\Core\Model\AbstractInfinitePaginableListParams;
|
||||
|
||||
use function Shlinkio\Shlink\Core\parseDateRangeFromQuery;
|
||||
|
||||
final class VisitsParams extends AbstractInfinitePaginableListParams
|
||||
class VisitsParams extends AbstractInfinitePaginableListParams
|
||||
{
|
||||
public readonly DateRange $dateRange;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user