Video validation add convenient validates

This commit is contained in:
Jérémy Munsch 2024-02-09 11:44:45 +01:00
parent e4a437694b
commit e6f3ec75c5
No known key found for this signature in database
GPG key ID: 18361AF3BFEC0FEC
2 changed files with 24 additions and 2 deletions

View file

@ -25,8 +25,19 @@ class IsValidVimeoId implements ValidationRule
public function validate(string $attribute, mixed $value, \Closure $fail): void
{
// phpcs:enable
if (!Str::of($value)->isMatch('/^[0-9]{8,10}$/')) {
if (!self::validates($value)) {
$fail(trans('validation.vimeo_id'));
}
}
/**
* Validate a value
*
* @param mixed $value
* @return boolean
*/
public static function validates(mixed $value): bool
{
return Str::of($value)->isMatch('/^[0-9]{8,10}$/');
}
}

View file

@ -26,8 +26,19 @@ class IsValidYoutubeId implements ValidationRule
public function validate(string $attribute, mixed $value, \Closure $fail): void
{
// phpcs:enable
if (!Str::of($value)->isMatch('/^[0-9A-Za-z_-]{10}[048AEIMQUYcgkosw]$/')) {
if (!self::validates($value)) {
$fail(trans('validation.youtube_id'));
}
}
/**
* Validate a value
*
* @param mixed $value
* @return boolean
*/
public static function validates(mixed $value): bool
{
return Str::of($value)->isMatch('/^[0-9A-Za-z_-]{10}[048AEIMQUYcgkosw]$/');
}
}