Skip to content

Commit 15da864

Browse files
committed
Additional little check to show how we're assumign the User object is the User entity
1 parent 7e7020d commit 15da864

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

cookbook/security/voters_data_permission.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ edit a particular object. Here's an example implementation::
118118
return VoterInterface::ACCESS_DENIED;
119119
}
120120

121+
// double-check that our User object is the entity we expect.
122+
// It always will be, unless we've configured our security system
123+
// in some other way.
124+
if (!$user instanceof User) {
125+
throw new \LogicException('The user is somehow not our User class!');
126+
}
127+
121128
switch($attribute) {
122129
case self::VIEW:
123130
// the data object could have for example a method isPrivate()

0 commit comments

Comments
 (0)