You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR was merged into the 2.8 branch.
Discussion
----------
Abstract voter tweaks
| Q | A
| ------------- | ---
| Bug fix? | yes (a little)
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
Based on suggestions from stof in #15870, this simplifies the BC and deprecation throwing code. This also adds a BadMethodCallException in case the user doesn't override `isGranted` *or* `voteOnAttribute`, because that's just plain wrong (as is calling `isGranted()` on the parent class directly, since that was formerly abstract).
Commits
-------
c03f5c2 Massively simplifying the BC and deprecated-throwing code thanks to suggestions by stof in #15870
@trigger_error(sprintf("The AbstractVoter::isGranted method is deprecated since 2.8 and won't be called anymore in 3.0. Override voteOnAttribute() instead.", $reflector->class), E_USER_DEPRECATED);
77
-
}
78
-
79
73
foreach ($attributesas$attribute) {
80
74
if (!$this->supports($attribute, $class)) {
81
75
continue;
@@ -84,16 +78,9 @@ public function vote(TokenInterface $token, $object, array $attributes)
84
78
// as soon as at least one attribute is supported, default is to deny access
85
79
$vote = self::ACCESS_DENIED;
86
80
87
-
if ($isNewOverwritten) {
88
-
if ($this->voteOnAttribute($attribute, $object, $token)) {
89
-
// grant access as soon as at least one voter returns a positive response
90
-
returnself::ACCESS_GRANTED;
91
-
}
92
-
} else {
93
-
if ($this->isGranted($attribute, $object, $token->getUser())) {
94
-
// grant access as soon as at least one voter returns a positive response
95
-
returnself::ACCESS_GRANTED;
96
-
}
81
+
if ($this->voteOnAttribute($attribute, $object, $token)) {
82
+
// grant access as soon as at least one voter returns a positive response
83
+
returnself::ACCESS_GRANTED;
97
84
}
98
85
}
99
86
@@ -191,7 +178,8 @@ protected function getSupportedAttributes()
// the user should override this method, and not rely on the deprecated isGranted()
203
+
@trigger_error(sprintf("The AbstractVoter::isGranted() method is deprecated since 2.8 and won't be called anymore in 3.0. Override voteOnAttribute() in %s instead.", get_class($this)), E_USER_DEPRECATED);
0 commit comments