File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 88use Sybio \PermissionBundle \Validation \PermissionValidatorInterface ;
99use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
1010use Symfony \Component \Security \Core \Authorization \Voter \Voter ;
11+ use function get_class ;
1112
1213/**
1314 * @extends Voter<string,PermissionInterface>
@@ -24,8 +25,11 @@ protected function supports(
2425 string $ attribute ,
2526 mixed $ subject ,
2627 ): bool {
27- return $ attribute === $ this ->securityAttribute
28- && $ subject instanceof PermissionInterface;
28+ return $ subject instanceof PermissionInterface
29+ && (
30+ $ attribute === $ this ->securityAttribute
31+ || $ attribute === get_class ($ subject )
32+ );
2933 }
3034
3135 /**
Original file line number Diff line number Diff line change @@ -42,6 +42,16 @@ public function it_supports_when_attribute_matches_and_subject_is_permission_int
4242 $ this ->assertSame (1 , $ result );
4343 }
4444
45+ #[Test]
46+ public function it_supports_when_attribute_matches_permission_class_and_subject_is_permission_interface (): void
47+ {
48+ $ permission = $ this ->createMock (PermissionInterface::class);
49+
50+ $ result = $ this ->voter ->vote ($ this ->token , $ permission , [$ permission ::class]);
51+
52+ $ this ->assertSame (1 , $ result );
53+ }
54+
4555 #[Test]
4656 public function it_does_not_support_when_attribute_does_not_match (): void
4757 {
You can’t perform that action at this time.
0 commit comments