diff options
author | Fabien Potencier <fabien.potencier@gmail.com> | 2015-10-05 09:15:26 +0200 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2015-10-05 09:15:26 +0200 |
commit | 88ef04f5d4cc2f895c7d74f6e5ba89255df9dc01 (patch) | |
tree | 42082c5790f2a782bdd7ac222a10228bf55774b6 | |
parent | bff03f8800d518efe8ccd579e1ac3b4f20c4d5bb (diff) | |
parent | 6a830f8b84ab0f22c06c090297bd8f45e24e8be4 (diff) | |
download | symfony-security-88ef04f5d4cc2f895c7d74f6e5ba89255df9dc01.zip symfony-security-88ef04f5d4cc2f895c7d74f6e5ba89255df9dc01.tar.gz symfony-security-88ef04f5d4cc2f895c7d74f6e5ba89255df9dc01.tar.bz2 |
feature #16102 Simplify AbstractVoter (Koc)
This PR was merged into the 2.8 branch.
Discussion
----------
Simplify AbstractVoter
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no, just simplification
| BC breaks? | no, because 2.8 is not yet released
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Commits
-------
93de659 Simplify AbstractVoter
-rw-r--r-- | Core/Authorization/Voter/AbstractVoter.php | 30 | ||||
-rw-r--r-- | Core/Tests/Authorization/Voter/AbstractVoterTest.php | 5 |
2 files changed, 8 insertions, 27 deletions
diff --git a/Core/Authorization/Voter/AbstractVoter.php b/Core/Authorization/Voter/AbstractVoter.php index 799c6f7..7b04222 100644 --- a/Core/Authorization/Voter/AbstractVoter.php +++ b/Core/Authorization/Voter/AbstractVoter.php @@ -68,10 +68,9 @@ abstract class AbstractVoter implements VoterInterface // 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; } @@ -88,25 +87,22 @@ abstract class AbstractVoter implements VoterInterface } /** - * 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. * * This method will become abstract in 3.0. * * @param string $attribute An attribute - * @param string $class The fully qualified class name of the passed object + * @param string $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 */ - protected function supports($attribute, $class) + protected function supports($attribute, $object) { @trigger_error('The getSupportedClasses and getSupportedAttributes methods are deprecated since version 2.8 and will be removed in version 3.0. Overwrite supports instead.', E_USER_DEPRECATED); $classIsSupported = false; foreach ($this->getSupportedClasses() as $supportedClass) { - if ($this->isClassInstanceOf($class, $supportedClass)) { + if ($object instanceof $supportedClass) { $classIsSupported = true; break; } @@ -124,20 +120,6 @@ abstract class AbstractVoter implements VoterInterface } /** - * 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); - } - - /** * Return an array of supported classes. This will be called by supportsClass. * * @return array an array of supported classes, i.e. array('Acme\DemoBundle\Model\Product') diff --git a/Core/Tests/Authorization/Voter/AbstractVoterTest.php b/Core/Tests/Authorization/Voter/AbstractVoterTest.php index 7062d39..5ea7732 100644 --- a/Core/Tests/Authorization/Voter/AbstractVoterTest.php +++ b/Core/Tests/Authorization/Voter/AbstractVoterTest.php @@ -84,10 +84,9 @@ class AbstractVoterTest_Voter extends AbstractVoter 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')); } } |