2020-04-26 19:09:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Rules;
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
|
|
|
|
|
|
class ImageData implements Rule
|
|
|
|
{
|
|
|
|
public function passes($attribute, $value): bool
|
|
|
|
{
|
2022-08-08 16:00:59 +00:00
|
|
|
return attempt(static function () use ($value) {
|
2020-12-22 20:11:22 +00:00
|
|
|
[$header,] = explode(';', $value);
|
2020-04-26 19:09:43 +00:00
|
|
|
|
2022-07-16 23:11:24 +00:00
|
|
|
return (bool) preg_match('/data:image\/(jpe?g|png|webp|gif)/i', $header);
|
2022-08-08 16:00:59 +00:00
|
|
|
}, false) ?? false;
|
2020-04-26 19:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function message(): string
|
|
|
|
{
|
|
|
|
return 'Invalid DataURL string';
|
|
|
|
}
|
|
|
|
}
|