framework
framework copied to clipboard
[filters] More flexibility in filters
It will be great if you can add some more flexibility to filters. I am talking about some control on errors list from filters. Now we have private property private \Spiral\Filters\Filter::$errors and we can use only getter. But in real systems it is general situation when we need to check some set of fields. For example in some request with fields ['filter1', 'dateFrom', 'dateTo'] it is required dateFrom or dateTo was defined. Current functionality can't help but if we will have some protected method like addError it can help.
Smth like:
protected function addError(string $field, string $message): void
{
if (array_key_exists($field, static::SCHEMA)
&& is_string($message) && Translator::isMessage($message)) {
$this->errors[$field] = $this->say($message);
}
}
@Eugentis You can use conditions:
[
'field1' => ['required', 'if' => ['withoutAll' => 'field2']],
'field2' => ['required', 'if' => ['withoutAll' => 'field1']],
]