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