Skip to content

Commit 327a52d

Browse files
Merge branch '2.8'
* 2.8: [Security] Deprecate "AbstractVoter" in favor of "Voter" [Security] Revert changes made between 2.7 and 2.8-beta Conflicts: UPGRADE-2.8.md src/Symfony/Component/Security/Core/Authorization/Voter/AbstractVoter.php src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AbstractVoterTest.php
2 parents 5183c88 + a58df11 commit 327a52d

File tree

3 files changed

+73
-87
lines changed

3 files changed

+73
-87
lines changed

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

Lines changed: 0 additions & 83 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Core\Authorization\Voter;
13+
14+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
15+
16+
/**
17+
* Voter is an abstract default implementation of a voter.
18+
*
19+
* @author Roman Marintšenko <inoryy@gmail.com>
20+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
21+
*/
22+
abstract class Voter implements VoterInterface
23+
{
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function vote(TokenInterface $token, $object, array $attributes)
28+
{
29+
// abstain vote by default in case none of the attributes are supported
30+
$vote = self::ACCESS_ABSTAIN;
31+
32+
foreach ($attributes as $attribute) {
33+
if (!$this->supports($attribute, $object)) {
34+
continue;
35+
}
36+
37+
// as soon as at least one attribute is supported, default is to deny access
38+
$vote = self::ACCESS_DENIED;
39+
40+
if ($this->voteOnAttribute($attribute, $object, $token)) {
41+
// grant access as soon as at least one attribute returns a positive response
42+
return self::ACCESS_GRANTED;
43+
}
44+
}
45+
46+
return $vote;
47+
}
48+
49+
/**
50+
* Determines if the attribute and subject are supported by this voter.
51+
*
52+
* @param string $attribute An attribute
53+
* @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type
54+
*
55+
* @return bool True if the attribute and subject are supported, false otherwise
56+
*/
57+
abstract protected function supports($attribute, $subject);
58+
59+
/**
60+
* Perform a single access check operation on a given attribute, subject and token.
61+
*
62+
* @param string $attribute
63+
* @param mixed $subject
64+
* @param TokenInterface $token
65+
*
66+
* @return bool
67+
*/
68+
abstract protected function voteOnAttribute($attribute, $subject, TokenInterface $token);
69+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
namespace Symfony\Component\Security\Core\Tests\Authorization\Voter;
1313

1414
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
15-
use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter;
15+
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
1616
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
1717

18-
class AbstractVoterTest extends \PHPUnit_Framework_TestCase
18+
class VoterTest extends \PHPUnit_Framework_TestCase
1919
{
2020
protected $token;
2121

@@ -50,13 +50,13 @@ public function getTests()
5050
*/
5151
public function testVote(array $attributes, $expectedVote, $object, $message)
5252
{
53-
$voter = new AbstractVoterTest_Voter();
53+
$voter = new VoterTest_Voter();
5454

5555
$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
5656
}
5757
}
5858

59-
class AbstractVoterTest_Voter extends AbstractVoter
59+
class VoterTest_Voter extends Voter
6060
{
6161
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
6262
{

0 commit comments

Comments
 (0)
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