<?php
declare(strict_types=1);
namespace App\Bundles\CatalogBundle\Security\Voter;
use App\Bundles\CatalogBundle\Entity\Catalog;
use App\Bundles\CatalogBundle\Enum\SystemCatalogAliasEnum;
use App\Bundles\UserBundle\Enum\SystemPermissionEnum;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class EditCatalogVoter extends Voter
{
protected function supports(string $attribute, $subject): bool
{
return $attribute === SystemPermissionEnum::SINGLE_CATALOG_EDIT->value;
}
/**
* @param Catalog $subject
*/
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
if (!$systemAlias = $subject->getSystemAlias()) {
return true;
}
return !in_array($systemAlias, SystemCatalogAliasEnum::getForbiddenEditAliases());
}
}