Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.2k
Open
Labels
Description
This code fragment correctly passes aTask
object to the TaskVoter "by name":
// TaskController.php#[Route('/{task}', name:'task_details', methods: ['GET'])]/* ↓↓↓↓ */#[IsGranted(TaskVoter::ACCESS_TASK,'task','No task found',404)]publicfunctiontaskDetails(Task$task):Response{// ...}// TaskVoter.phpprotectedfunctionvoteOnAttribute(string$attribute,$subject,TokenInterface$token):bool{if (TaskVoter::ACCESS_TASK ===$attribute &&$subjectinstanceof Task) {return$this->canAccessTask($subject,$token->getUser()); }}
This is pretty handy, although I cannot find documentation about it anywhere. I'd expect it in(Security->Add Code to Deny Access) Securing Controllers and Other Code.
It is used throughoutVoters->Setup: Checking for Access in a Controller.