mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
32 lines
795 B
PHP
32 lines
795 B
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use App\Services\Helpers\ScrapeStrategyHelper;
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Translation\PotentiallyTranslatedString;
|
|
|
|
class ValidScrapeStrategy implements ValidationRule
|
|
{
|
|
/**
|
|
* Run the validation rule.
|
|
*
|
|
* @param Closure(string, ?string=): PotentiallyTranslatedString $fail
|
|
*/
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
if (! is_array($value)) {
|
|
$fail('The :attribute must be an array.');
|
|
|
|
return;
|
|
}
|
|
|
|
$result = ScrapeStrategyHelper::validate($value);
|
|
|
|
if ($result !== true) {
|
|
$fail('The :attribute has invalid field definitions: '.implode(', ', $result));
|
|
}
|
|
}
|
|
}
|