Remove AbstractVoter#isGranted() method
This commit is contained in:
parent
6b6de15676
commit
6f9e8977ce
@ -97,38 +97,9 @@ abstract class AbstractVoter implements VoterInterface
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param object $object
|
||||
* @param UserInterface|string $user
|
||||
*
|
||||
* @deprecated This method will be removed in 3.0 - override voteOnAttribute instead.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isGranted($attribute, $object, $user = null)
|
||||
{
|
||||
// forces isGranted() or voteOnAttribute() to be overridden
|
||||
throw new \BadMethodCallException(sprintf('You must override the voteOnAttribute() method in "%s".', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a single access check operation on a given attribute, object and (optionally) user
|
||||
* It is safe to assume that $attribute and $object's class pass supportsAttribute/supportsClass
|
||||
* $user can be one of the following:
|
||||
* a UserInterface object (fully authenticated user)
|
||||
* a string (anonymously authenticated user).
|
||||
*
|
||||
* This method will become abstract in 3.0.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param object $object
|
||||
* @param TokenInterface $token
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
|
||||
{
|
||||
// the user should override this method, and not rely on the deprecated isGranted()
|
||||
@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);
|
||||
|
||||
return $this->isGranted($attribute, $object, $token->getUser());
|
||||
}
|
||||
abstract protected function voteOnAttribute($attribute, $object, TokenInterface $token);
|
||||
}
|
||||
|
@ -54,27 +54,6 @@ class AbstractVoterTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTests
|
||||
* @group legacy
|
||||
*/
|
||||
public function testVoteLegacy(array $attributes, $expectedVote, $object, $message)
|
||||
{
|
||||
$voter = new AbstractVoterTest_LegacyVoter();
|
||||
|
||||
$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedException \BadMethodCallException
|
||||
*/
|
||||
public function testNoOverriddenMethodsThrowsException()
|
||||
{
|
||||
$voter = new AbstractVoterTest_NothingImplementedVoter();
|
||||
$voter->vote($this->token, new \stdClass(), array('EDIT'));
|
||||
}
|
||||
}
|
||||
|
||||
class AbstractVoterTest_Voter extends AbstractVoter
|
||||
@ -90,36 +69,3 @@ class AbstractVoterTest_Voter extends AbstractVoter
|
||||
&& in_array($attribute, array('EDIT', 'CREATE'));
|
||||
}
|
||||
}
|
||||
|
||||
class AbstractVoterTest_LegacyVoter extends AbstractVoter
|
||||
{
|
||||
protected function getSupportedClasses()
|
||||
{
|
||||
return array('stdClass');
|
||||
}
|
||||
|
||||
protected function getSupportedAttributes()
|
||||
{
|
||||
return array('EDIT', 'CREATE');
|
||||
}
|
||||
|
||||
protected function isGranted($attribute, $object, $user = null)
|
||||
{
|
||||
return 'EDIT' === $attribute;
|
||||
}
|
||||
}
|
||||
|
||||
class AbstractVoterTest_NothingImplementedVoter extends AbstractVoter
|
||||
{
|
||||
protected function getSupportedClasses()
|
||||
{
|
||||
return array('stdClass');
|
||||
}
|
||||
|
||||
protected function getSupportedAttributes()
|
||||
{
|
||||
return array('EDIT', 'CREATE');
|
||||
}
|
||||
|
||||
// this is a bad voter that hasn't overridden isGranted or voteOnAttribute
|
||||
}
|
||||
|
Reference in New Issue
Block a user