src/Security/Voter/Channel/CanShareContentVoter.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter\Channel;
  3. use App\Entity\Channel\Channel;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  6. /**
  7. * TODO Generalize Voter to manage available actions for given Channel
  8. * => Only share Content for the moment
  9. */
  10. class CanShareContentVoter extends Voter
  11. {
  12. const CHANNEL_PERM_SHARE_CONTENT = 'CHANNEL_PERM_SHARE_CONTENT';
  13. public function supportsAttribute(string $attribute): bool
  14. {
  15. return $attribute === self::CHANNEL_PERM_SHARE_CONTENT;
  16. }
  17. public function supportsType(string $subjectType): bool
  18. {
  19. return $subjectType === Channel::class;
  20. }
  21. function supports(string $attribute, $subject): bool
  22. {
  23. return $this->supportsType($subject::class) && $this->supportsAttribute($attribute);
  24. }
  25. protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
  26. {
  27. if ($subject->isCanShareContent()) {
  28. return true;
  29. }
  30. return false;
  31. }
  32. }