mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-12 01:54:41 +08:00
Allow filtering orphan visits by type from the CLI
This commit is contained in:
@@ -20,6 +20,7 @@ use function array_keys;
|
||||
use function array_map;
|
||||
use function array_reduce;
|
||||
use function date_default_timezone_get;
|
||||
use function implode;
|
||||
use function is_array;
|
||||
use function print_r;
|
||||
use function Shlinkio\Shlink\Common\buildDateRange;
|
||||
@@ -182,3 +183,11 @@ function enumValues(string $enum): array
|
||||
$cache[$enum] = array_map(static fn (BackedEnum $type) => (string) $type->value, $enum::cases())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<BackedEnum> $enum
|
||||
*/
|
||||
function enumToString(string $enum): string
|
||||
{
|
||||
return sprintf('["%s"]', implode('", "', enumValues($enum)));
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@ 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 Shlinkio\Shlink\Core\enumToString;
|
||||
use function sprintf;
|
||||
|
||||
final class OrphanVisitsParams extends VisitsParams
|
||||
@@ -43,9 +42,9 @@ final class OrphanVisitsParams extends VisitsParams
|
||||
} catch (ValueError) {
|
||||
throw ValidationException::fromArray([
|
||||
'type' => sprintf(
|
||||
'%s is not a valid orphan visit type. Expected one of ["%s"]',
|
||||
'%s is not a valid orphan visit type. Expected one of %s',
|
||||
$type,
|
||||
implode('", "', enumValues(OrphanVisitType::class)),
|
||||
enumToString(OrphanVisitType::class),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user