In Symfony 3.4, is there a way to validate optional input GET parameters passed in through the querystring as integers?
If provided, I am using the $ownerId
and $courseId
to query the corresponding repositories, however the value needs to be an integer otherwise the query falls over.
This is what I have so far and it matches the docs, but it doesn't seem to force any validation or graceful handling of passing through http://www.crmpicco.co.uk/book-teeoff/belleisle/ayrshire/?ownerid=crmpicco&courseId=rfc1872, for example.
/**
* @Route(
* "/book-teeoff/{course}/{area}",
* name = "book_teeoff",
* requirements={"ownerId"="\d+","courseId"="\d+"},
* methods={"GET"}
* )
*
* @param Request $request
*
* @return Response
*/
public function bookTeeoffAction(Request $request): Response
{
// these are *optional*, but if provided need to be integers
$ownerId = $request->get('ownerId');
$courseId = $request->get('courseId');