11
11
12
12
namespace Symfony \Cmf \Bundle \CoreBundle \Security \Authorization \Voter ;
13
13
14
+ use function is_subclass_of ;
15
+ use Symfony \Cmf \Bundle \CoreBundle \PublishWorkflow \PublishableReadInterface ;
16
+ use Symfony \Cmf \Bundle \CoreBundle \PublishWorkflow \PublishTimePeriodReadInterface ;
14
17
use Symfony \Cmf \Bundle \CoreBundle \PublishWorkflow \PublishWorkflowChecker ;
15
18
use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
16
- use Symfony \Component \Security \Core \Authorization \Voter \VoterInterface ;
19
+ use Symfony \Component \Security \Core \Authorization \Voter \Voter ;
17
20
18
21
/**
19
22
* This is a security voter registered with the Symfony security system that
20
23
* brings the publish workflow into standard Symfony security.
21
24
*
22
25
* @author David Buchmann <[email protected] >
23
26
*/
24
- class PublishedVoter implements VoterInterface
27
+ class PublishedVoter extends Voter
25
28
{
26
29
/**
27
30
* @var PublishWorkflowChecker
@@ -36,41 +39,27 @@ public function __construct(PublishWorkflowChecker $publishWorkflowChecker)
36
39
/**
37
40
* {@inheritdoc}
38
41
*/
39
- public function supportsAttribute ($ attribute )
42
+ public function supportsAttribute ($ attribute ): bool
40
43
{
41
44
return PublishWorkflowChecker::VIEW_ATTRIBUTE === $ attribute
42
45
|| PublishWorkflowChecker::VIEW_ANONYMOUS_ATTRIBUTE === $ attribute
43
46
;
44
47
}
45
48
46
- /**
47
- * {@inheritdoc}
48
- */
49
- public function supportsClass ($ class )
49
+ public function supportsType (string $ subjectType ): bool
50
50
{
51
- return $ this ->publishWorkflowChecker ->supportsClass ($ class );
51
+ return is_subclass_of ($ subjectType , PublishableReadInterface::class)
52
+ || is_subclass_of ($ subjectType , PublishTimePeriodReadInterface::class);
52
53
}
53
54
54
- /**
55
- * {@inheritdoc}
56
- *
57
- * @param object $subject
58
- */
59
- public function vote (TokenInterface $ token , $ subject , array $ attributes )
55
+ protected function supports ($ attribute , $ subject )
60
56
{
61
- if (!\is_object ($ subject ) || !$ this ->supportsClass (\get_class ($ subject ))) {
62
- return self ::ACCESS_ABSTAIN ;
63
- }
64
- foreach ($ attributes as $ attribute ) {
65
- if (!$ this ->supportsAttribute ($ attribute )) {
66
- return self ::ACCESS_ABSTAIN ;
67
- }
68
- }
69
-
70
- if ($ this ->publishWorkflowChecker ->isGranted ($ attributes , $ subject )) {
71
- return self ::ACCESS_GRANTED ;
72
- }
57
+ return \is_object ($ subject ) && $ this ->supportsType (\get_class ($ subject ))
58
+ && $ this ->supportsAttribute ($ attribute );
59
+ }
73
60
74
- return self ::ACCESS_DENIED ;
61
+ protected function voteOnAttribute ($ attribute , $ subject , TokenInterface $ token )
62
+ {
63
+ return $ this ->publishWorkflowChecker ->isGranted ($ attribute , $ subject );
75
64
}
76
65
}
0 commit comments