src/Bundles/CatalogBundle/Security/Voter/EditCatalogVoter.php line 13

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Bundles\CatalogBundle\Security\Voter;
  4. use App\Bundles\CatalogBundle\Entity\Catalog;
  5. use App\Bundles\CatalogBundle\Enum\SystemCatalogAliasEnum;
  6. use App\Bundles\UserBundle\Enum\SystemPermissionEnum;
  7. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  8. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  9. class EditCatalogVoter extends Voter
  10. {
  11.     protected function supports(string $attribute$subject): bool
  12.     {
  13.         return $attribute === SystemPermissionEnum::SINGLE_CATALOG_EDIT->value;
  14.     }
  15.     /**
  16.      * @param Catalog $subject
  17.      */
  18.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  19.     {
  20.         if ($subject->isHidden()) {
  21.             return false;
  22.         }
  23.         if (!$systemAlias $subject->getSystemAlias()) {
  24.             return true;
  25.         }
  26.         return !in_array($systemAliasSystemCatalogAliasEnum::getForbiddenEditAliases());
  27.     }
  28. }