diff --git a/UPGRADE-3.0.md b/UPGRADE-3.0.md index dba1d48be33c2..288c9754d7a06 100644 --- a/UPGRADE-3.0.md +++ b/UPGRADE-3.0.md @@ -758,6 +758,38 @@ UPGRADE FROM 2.x to 3.0 * The `supportsAttribute()` and `supportsClass()` methods of classes `AuthenticatedVoter`, `ExpressionVoter` and `RoleVoter` have been removed. + * The `AbstractVoter::supports()` method signature have changed: second argument now is object instead of class name. + + Before: + + ```php + class MyVoter extends AbstractVoter + { + protected function supports($attribute, $class) + { + return 'EDIT' === $attribute && $this->isClassInstanceOf($class, 'Topic'); + } + + // ... + } + ``` + + After: + + ```php + class MyVoter extends AbstractVoter + { + protected function supports($attribute, $object) + { + return 'EDIT' === $attribute && $object instanceof Topic; + } + + // ... + } + ``` + + * The `isClassInstanceOf()` method of classe `AbstractVoter` have been removed. + ### Translator * The `Translator::setFallbackLocale()` method has been removed in favor of diff --git a/src/Symfony/Component/Security/Core/Authorization/Voter/AbstractVoter.php b/src/Symfony/Component/Security/Core/Authorization/Voter/AbstractVoter.php index 71f570f15e22a..1df12d1927958 100644 --- a/src/Symfony/Component/Security/Core/Authorization/Voter/AbstractVoter.php +++ b/src/Symfony/Component/Security/Core/Authorization/Voter/AbstractVoter.php @@ -17,6 +17,7 @@ * Abstract Voter implementation that reduces boilerplate code required to create a custom Voter. * * @author Roman Marintšenko + * @author Konstantin Myakshin */ abstract class AbstractVoter implements VoterInterface { @@ -41,10 +42,9 @@ public function vote(TokenInterface $token, $object, array $attributes) // abstain vote by default in case none of the attributes are supported $vote = self::ACCESS_ABSTAIN; - $class = get_class($object); foreach ($attributes as $attribute) { - if (!$this->supports($attribute, $class)) { + if (!$this->supports($attribute, $object)) { continue; } @@ -61,31 +61,14 @@ public function vote(TokenInterface $token, $object, array $attributes) } /** - * Determines if the attribute and class are supported by this voter. - * - * To determine if the passed class is instance of the supported class, the - * isClassInstanceOf() method can be used. + * Determines if the attribute and object are supported by this voter. * * @param string $attribute An attribute - * @param string $class The fully qualified class name of the passed object + * @param object $object The object to secure * - * @return bool True if the attribute and class is supported, false otherwise + * @return bool True if the attribute and object is supported, false otherwise */ - abstract protected function supports($attribute, $class); - - /** - * A helper method to test if the actual class is instanceof or equal - * to the expected class. - * - * @param string $actualClass The actual class name - * @param string $expectedClass The expected class name - * - * @return bool - */ - protected function isClassInstanceOf($actualClass, $expectedClass) - { - return $expectedClass === $actualClass || is_subclass_of($actualClass, $expectedClass); - } + abstract protected function supports($attribute, $object); /** * Perform a single access check operation on a given attribute, object and token. diff --git a/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AbstractVoterTest.php b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AbstractVoterTest.php index aafef5a7a648d..537dc4c161971 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AbstractVoterTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AbstractVoterTest.php @@ -63,9 +63,8 @@ protected function voteOnAttribute($attribute, $object, TokenInterface $token) return 'EDIT' === $attribute; } - protected function supports($attribute, $class) + protected function supports($attribute, $object) { - return $this->isClassInstanceOf($class, 'stdClass') - && in_array($attribute, array('EDIT', 'CREATE')); + return $object instanceof \stdClass && in_array($attribute, array('EDIT', 'CREATE')); } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy