10000 Remove AbstractVoter#isGranted() method · symfony/symfony@6f9e897 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6f9e897

Browse files
committed
Remove AbstractVoter#isGranted() method
1 parent 6b6de15 commit 6f9e897

File tree

2 files changed

+1
-84
lines changed

2 files changed

+1
-84
lines changed

src/Symfony/Component/Security/Core/Authorization/Voter/AbstractVoter.php

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -95,40 +95,11 @@ protected function isClassInstanceOf($actualClass, $expectedClass)
9595
* a UserInterface object (fully authenticated user)
9696
* a string (anonymously authenticated user).
9797
*
98-
* @param string $attribute
99-
* @param object $object
100-
* @param UserInterface|string $user
101-
*
102-
* @deprecated This method will be removed in 3.0 - override voteOnAttribute instead.
103-
*
104-
* @return bool
105-
*/
106-
protected function isGranted($attribute, $object, $user = null)
107-
{
108-
// forces isGranted() or voteOnAttribute() to be overridden
109-
throw new \BadMethodCallException(sprintf('You must override the voteOnAttribute() method in "%s".', get_class($this)));
110-
}
111-
112-
/**
113-
* Perform a single access check operation on a given attribute, object and (optionally) user
114-
* It is safe to assume that $attribute and $object's class pass supportsAttribute/supportsClass
115-
* $user can be one of the following:
116-
* a UserInterface object (fully authenticated user)
117-
* a string (anonymously authenticated user).
118-
*
119-
* This method will become abstract in 3.0.
120-
*
12198
* @param string $attribute
12299
* @param object $object
123100
* @param TokenInterface $token
124101
*
125102
* @return bool
126103
*/
127-
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
128-
{
129-
// the user should override this method, and not rely on the deprecated isGranted()
130-
@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);
131-
132-
return $this->isGranted($attribute, $object, $token->getUser());
133-
}
104+
abstract protected function voteOnAttribute($attribute, $object, TokenInterface $token);
134105
}

src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AbstractVoterTest.php

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,6 @@ public function testVote(array $attributes, $expectedVote, $object, $message)
5454

5555
$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
5656
}
57-
58-
/**
59-
* @dataProvider getTests
60-
* @group legacy
61-
*/
62-
public function testVoteLegacy(array $attributes, $expectedVote, $object, $message)
63-
{
64-
$voter = new AbstractVoterTest_LegacyVoter();
65-
66-
$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
67-
}
68-
69-
/**
70-
* @group legacy
71-
* @expectedException \BadMethodCallException
72-
*/
73-
public function testNoOverriddenMethodsThrowsException()
74-
{
75-
$voter = new AbstractVoterTest_NothingImplementedVoter();
76-
$voter->vote($this->token, new \stdClass(), array('EDIT'));
77-
}
7857
}
7958

8059
class AbstractVoterTest_Voter extends AbstractVoter
@@ -90,36 +69,3 @@ protected function supports($attribute, $class)
9069
&& in_array($attribute, array('EDIT', 'CREATE'));
9170
}
9271
}
93-
94-
class AbstractVoterTest_LegacyVoter extends AbstractVoter
95-
{
96-
protected function getSupportedClasses()
97-
{
98-
return array('stdClass');
99-
}
100-
101-
protected function getSupportedAttributes()
102-
{
103-
return array('EDIT', 'CREATE');
104-
}
105-
106-
protected function isGranted($attribute, $object, $user = null)
107-
{
108-
return 'EDIT' === $attribute;
109-
}
110-
}
111-
112-
class AbstractVoterTest_NothingImplementedVoter extends AbstractVoter
113-
{
114-
protected function getSupportedClasses()
115-
{
116-
return array('stdClass');
117-
}
118-
119-
protected function getSupportedAttributes()
120-
{
121-
return array('EDIT', 'CREATE');
122-
}
123-
124-
// this is a bad voter that hasn't overridden isGranted or voteOnAttribute
125-
}

0 commit comments

Comments
 (0)
0