koel/app/Rules/ImageData.php

22 lines
481 B
PHP
Raw Normal View History

<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
2024-01-10 00:47:09 +00:00
use Illuminate\Support\Str;
class ImageData implements Rule
{
public function passes($attribute, $value): bool
{
2022-08-08 16:00:59 +00:00
return attempt(static function () use ($value) {
2024-01-10 00:47:09 +00:00
return (bool) preg_match('/data:image\/(jpe?g|png|webp|gif)/i', Str::before($value, ';'));
2022-08-08 16:00:59 +00:00
}, false) ?? false;
}
public function message(): string
{
return 'Invalid DataURL string';
}
}