2021-10-10 18:05:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Rules;
|
|
|
|
|
|
|
|
use App\Values\SmartPlaylistRule;
|
|
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
|
|
use Throwable;
|
|
|
|
|
|
|
|
class ValidSmartPlaylistRulePayload implements Rule
|
|
|
|
{
|
|
|
|
/** @param array $value */
|
|
|
|
public function passes($attribute, $value): bool
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
foreach ((array) $value as $ruleGroupConfig) {
|
|
|
|
foreach ($ruleGroupConfig['rules'] as $rule) {
|
|
|
|
SmartPlaylistRule::assertConfig($rule, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2022-07-06 11:05:21 +00:00
|
|
|
} catch (Throwable) {
|
2021-10-10 18:05:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function message(): string
|
|
|
|
{
|
|
|
|
return 'Invalid smart playlist rules';
|
|
|
|
}
|
|
|
|
}
|