1 | <?php |
||
28 | class PermissionVoter extends Voter |
||
29 | { |
||
30 | private const TYPE_BOOLEAN = 'TYPE_BOOLEAN'; |
||
31 | private const TYPE_ROLE = 'TYPE_ROLE'; |
||
32 | private const TYPE_MEMBER_ROLE = 'TYPE_MEMBER_ROLE'; |
||
33 | |||
34 | private $attributeMap = [ |
||
35 | PermissionEnum::PARKING_AVAILABILITY_CREATE => [self::TYPE_BOOLEAN, Availability::class, false], |
||
36 | PermissionEnum::PARKING_AVAILABILITY_READ => [self::TYPE_BOOLEAN, Availability::class, true], |
||
37 | PermissionEnum::PARKING_AVAILABILITY_UPDATE => [self::TYPE_BOOLEAN, Availability::class, false], |
||
38 | PermissionEnum::PARKING_AVAILABILITY_DELETE => [self::TYPE_BOOLEAN, Availability::class, false], |
||
39 | |||
40 | PermissionEnum::PARKING_AVAILABILITY_BREAK_CREATE => [self::TYPE_BOOLEAN, AvailabilityBreak::class, false], |
||
41 | PermissionEnum::PARKING_AVAILABILITY_BREAK_READ => [self::TYPE_BOOLEAN, AvailabilityBreak::class, true], |
||
42 | PermissionEnum::PARKING_AVAILABILITY_BREAK_UPDATE => [self::TYPE_BOOLEAN, AvailabilityBreak::class, false], |
||
43 | PermissionEnum::PARKING_AVAILABILITY_BREAK_DELETE => [self::TYPE_BOOLEAN, AvailabilityBreak::class, false], |
||
44 | |||
45 | PermissionEnum::PARKING_MEMBER_CREATE => [self::TYPE_ROLE, Member::class, false], |
||
46 | PermissionEnum::PARKING_MEMBER_READ => [self::TYPE_BOOLEAN, Member::class, true], |
||
47 | PermissionEnum::PARKING_MEMBER_UPDATE => [self::TYPE_ROLE, Member::class, false], |
||
48 | PermissionEnum::PARKING_MEMBER_DELETE => [self::TYPE_ROLE, Member::class, false], |
||
49 | |||
50 | PermissionEnum::PARKING_MEMBER_NEED_CREATE => [self::TYPE_MEMBER_ROLE, MemberNeed::class, false], |
||
51 | PermissionEnum::PARKING_MEMBER_NEED_READ => [self::TYPE_BOOLEAN, MemberNeed::class, true], |
||
52 | PermissionEnum::PARKING_MEMBER_NEED_UPDATE => [self::TYPE_MEMBER_ROLE, MemberNeed::class, false], |
||
53 | PermissionEnum::PARKING_MEMBER_NEED_DELETE => [self::TYPE_MEMBER_ROLE, MemberNeed::class, false], |
||
54 | |||
55 | PermissionEnum::PARKING_MEMBERSHIP_CREATE => [self::TYPE_MEMBER_ROLE, Membership::class, false], |
||
56 | PermissionEnum::PARKING_MEMBERSHIP_READ => [self::TYPE_BOOLEAN, Membership::class, true], |
||
57 | PermissionEnum::PARKING_MEMBERSHIP_UPDATE => [self::TYPE_MEMBER_ROLE, Membership::class, false], |
||
58 | PermissionEnum::PARKING_MEMBERSHIP_DELETE => [self::TYPE_MEMBER_ROLE, Membership::class, false], |
||
59 | |||
60 | PermissionEnum::PARKING_RESERVATION_CREATE => [self::TYPE_MEMBER_ROLE, Reservation::class, false], |
||
61 | PermissionEnum::PARKING_RESERVATION_READ => [self::TYPE_BOOLEAN, Reservation::class, true], |
||
62 | PermissionEnum::PARKING_RESERVATION_UPDATE => [self::TYPE_MEMBER_ROLE, Reservation::class, false], |
||
63 | PermissionEnum::PARKING_RESERVATION_DELETE => [self::TYPE_MEMBER_ROLE, Reservation::class, false], |
||
64 | ]; |
||
65 | |||
66 | /** @var ConfigurationService */ |
||
67 | private $configurationService; |
||
68 | /** @var LoggerInterface */ |
||
69 | private $logger; |
||
70 | |||
71 | //------------------------------------------------------------------------------------------------------------------ |
||
72 | |||
73 | 20 | public function __construct(ConfigurationService $configurationService, LoggerInterface $logger) |
|
78 | |||
79 | //------------------------------------------------------------------------------------------------------------------ |
||
80 | |||
81 | /** |
||
82 | * @param string $attribute |
||
83 | * @param object|mixed $subject |
||
84 | */ |
||
85 | 20 | protected function supports($attribute, $subject): bool |
|
108 | |||
109 | /** |
||
110 | * @param string|mixed $attribute |
||
111 | * @param object|mixed $subject |
||
112 | */ |
||
113 | 16 | protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool |
|
154 | |||
155 | //------------------------------------------------------------------------------------------------------------------ |
||
156 | |||
157 | 20 | private function isAttributeSupported(string $attribute): bool |
|
161 | |||
162 | 16 | private function getAttributeConfiguration(string $attribute): PermissionData |
|
172 | |||
173 | 16 | private function getLoggedInMember(TokenInterface $token): ?Member |
|
186 | |||
187 | /** |
||
188 | * @param string|mixed $attribute |
||
189 | * @param object|mixed $subject |
||
190 | */ |
||
191 | 16 | private function assertAttributeAndSubject($attribute, $subject): void |
|
197 | |||
198 | 8 | protected function voteOnAttributeBoolean(string $attribute, Member $loggedInMember): bool |
|
206 | |||
207 | 10 | protected function voteOnAttributeRole(string $attribute, GetRoleInterface $subject, Member $loggedInMember): bool |
|
216 | |||
217 | 1 | protected function voteOnAttributeMemberRole(string $attribute, GetMemberInterface $subject, Member $loggedInMember): bool |
|
234 | |||
235 | /** |
||
236 | * @param object|mixed $subject |
||
237 | */ |
||
238 | 10 | private function assertSubjectHasRole($subject): void |
|
244 | |||
245 | /** |
||
246 | * @param object|mixed $subject |
||
247 | */ |
||
248 | 1 | private function assertSubjectHasMember($subject): void |
|
254 | } |
||
255 |