I have an action defined as
public function someAction(Something $something) {
...
}
I would like to use the token parameter passed as the βnormalβ query string parameter, for example:
/myController/doSomething/5?token=2a47c2ff18a5d53cbaa5840b6c7c4008
What would be a suitable way to make this parameter necessary and establish some requirements for it, for example, to comply ^[\da-z]+$? Is there a way to indicate this in annotation syntax?
As I see it, this will do it manually, for example:
public function someAction(Something $something, Request $request) {
$token = $request->query->get('token');
$regexConstrain = new Regex('^[\da-z]+$');
$regexConstrain->message = 'Invalid token';
$errors = $this->get('validator')->validate($token, $regexConstrain);
if (count($errors)) {
throw new \InvalidArgumentException($errors[0]->getMessage());
}
...
}
But is there a faster, built-in way to do this?
source
share