src/Security/FeatureAccessVoter.php line 9

Open in your IDE?
  1. <?php
  2. // src/Security/FeatureAccessVoter.php
  3. namespace App\Security;
  4. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use App\Service\ShopManager// سرویسی که siteAccess داخلشه
  7. class FeatureAccessVoter extends Voter
  8. {
  9.     public const FEATURE_ACCESS 'FEATURE_ACCESS';
  10.     public function __construct(private ShopManager $shopAccessService)
  11.     {
  12.     }
  13.     protected function supports(string $attribute$subject): bool
  14.     {
  15.         return $attribute === 'FEATURE_ACCESS' && is_string($subject);
  16.     }
  17.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  18.     {
  19.         // $subject در اینجا featureKey هست
  20.         return $this->shopAccessService->siteAccessDeny($subject);
  21.     }
  22. }