简体   繁体   中英

Validation for arrays in ParamFetcher Symfony FOSRestBundle

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM