src/Security/Voter/Library/PersonalLibraryVoter.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voter\Library;
  3. use App\Entity\PersonalFolder;
  4. use App\Entity\PersonalResource;
  5. use App\Entity\User;
  6. /**
  7.  * Class PersonalLibraryVoter.
  8.  */
  9. class PersonalLibraryVoter extends LibraryVoter
  10. {
  11.     /**
  12.      * {@inheritdoc}
  13.      */
  14.     protected function supports($attribute$subject): bool
  15.     {
  16.         return in_array($attributeself::PERMISSIONS) &&
  17.             ($subject instanceof PersonalResource || $subject instanceof PersonalFolder);
  18.     }
  19.     /**
  20.      * {@inheritdoc}
  21.      */
  22.     public function canDelete($resourceUser $user): bool
  23.     {
  24.         return $resource->getUser()->getId() === $user->getId();
  25.     }
  26.     /**
  27.      * {@inheritdoc}
  28.      */
  29.     public function canStar($resourceUser $user): bool
  30.     {
  31.         return $resource->getUser()->getId() === $user->getId();
  32.     }
  33.     /**
  34.      * {@inheritdoc}
  35.      */
  36.     public function canRestore($resourceUser $user): bool
  37.     {
  38.         return $resource->getUser()->getId() === $user->getId();
  39.     }
  40.     /**
  41.      * {@inheritdoc}
  42.      */
  43.     public function canPermanentDelete($resourceUser $user): bool
  44.     {
  45.         return $resource->getUser()->getId() === $user->getId();
  46.     }
  47.     /**
  48.      * {@inheritdoc}
  49.      */
  50.     public function canDownload($resourceUser $user): bool
  51.     {
  52.         return $resource->getUser()->getId() === $user->getId();
  53.     }
  54.     /**
  55.      * {@inheritdoc}
  56.      */
  57.     public function canEditName($resourceUser $user): bool
  58.     {
  59.         return $resource->getUser()->getId() === $user->getId();
  60.     }
  61. }