8000 [3.0][Security] Remove deprecated features by wouterj · Pull Request #15899 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[3.0][Security] Remove deprecated features #15899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 30, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit 8000
Next Next commit
Remove AbstractVoter#isGranted() method
  • Loading branch information
wouterj committed Sep 30, 2015
commit 6f9e8977ce1dae6809f2f6ac271b9df3eb4d8e01
Original file line number Diff line number Diff line change
Expand Up @@ -95,40 +95,11 @@ protected function isClassInstanceOf($actualClass, $expectedClass)
* a UserInterface object (fully authenticated user)
* a string (anonymously authenticated user).
*
* @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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,6 @@ public function testVote(array $attributes, $expectedVote, $object, $message)

$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
Expand All @@ -90,36 +69,3 @@ protected function supports($attribute, $class)
&& 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
}
0