koel/app/Rules/ValidSmartPlaylistRulePayload.php

21 lines
529 B
PHP
Raw Normal View History

<?php
namespace App\Rules;
use App\Values\SmartPlaylistRuleGroupCollection;
2024-05-19 05:49:42 +00:00
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Arr;
2024-05-19 05:49:42 +00:00
class ValidSmartPlaylistRulePayload implements ValidationRule
{
2024-05-19 05:49:42 +00:00
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$passes = (bool) rescue(static fn () => SmartPlaylistRuleGroupCollection::create(Arr::wrap($value)));
2024-05-19 05:49:42 +00:00
if (!$passes) {
$fail('Invalid smart playlist rules');
}
}
}