Validation for arrays in ParamFetcher Symfony FOSRestBundle

1k Views Asked by At

I need some validation for array attributes in my ParamFetcher params:

Example:

/**
* @RequestParam(name="client[name]", strict=true, requirements="...")
* @RequestParam(name="client[phone]", strict=true, requirements="...")
*/
public function createAction(ParamFetcherInterface $paramFetcher) 
{
  //...
}

How I can do this? Maybe you have alternative ways to do this? Using ParamFetcher not necessary

1

There are 1 best solutions below

0
On

You should maybe have a look at the OptionsResolver Component of Symfony.

You could easily implements your own logic to "client" defining mandatory keys, default values, validations... and manage triggered errors to throw BadRequestException and return detailed errors.