Description
Description
Hello,
What do you think about providing helpers to get request or query parameter value using the request object with same behavior as what can be done using the requirements
in routes (for query params). If the value doesn't matches the requirements, the method throw a BadRequestException.
The goal would be to avoid boilerplate like this:
$formDefinitionId = $request->request->get('formDefId');
if (preg_match('/\d+/', $formDefinitionId)) {
$formDefinitionId = (int) $formDefinitionId;
} else {
throw new BadRequestHttpException('Invalid request parameter: "formDefId"');
}
It would be nice to call a method like this:
$formDefinitionId = (int) $request->request->getForRequirement('formDefId', '\d+');
In that case if the parameter value does not match the requirement it automatically throw a BadRequestHttpException.
This is a small thing but I always encounter projects that does not manage correctly/safely the request parameters due to the lack of such helper. In most case I find the following call:
$formDefinitionId = $request->request->getInt('formDefId');
Rather than returning a BadRequest, the process is done with $formDefinitionId = 0 which can lead to unexpected queries etc.