framework icon indicating copy to clipboard operation
framework copied to clipboard

[filters] More flexibility in filters

Open Eugentis opened this issue 6 years ago • 1 comments

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 avatar Jan 23 '20 14:01 Eugentis

@Eugentis You can use conditions:

[
    'field1' => ['required', 'if' => ['withoutAll' => 'field2']],
    'field2' => ['required', 'if' => ['withoutAll' => 'field1']],
]

vvval avatar Dec 01 '20 15:12 vvval