bundles/PublicApiBundle/Security/Authorization/Voter/MerchantOwnerVoter.php line 12

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Bdm\PublicApiBundle\Security\Authorization\Voter;
  4. use Bdm\BackofficeBundle\Entity\MerchantAwareInterface;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use function is_object;
  7. class MerchantOwnerVoter extends AbstractVoter
  8. {
  9. /**
  10. * @param string $sAttribute attribute
  11. * @param mixed $oSubject subject
  12. * @return bool
  13. */
  14. public function supports($sAttribute, $oSubject)
  15. {
  16. return is_object($oSubject) && $oSubject instanceof MerchantAwareInterface;
  17. }
  18. /**
  19. * @param string $sAttr attr
  20. * @param mixed $mEntity entity
  21. * @param TokenInterface $oToken token
  22. *
  23. * @return bool
  24. */
  25. protected function voteOnAttribute($sAttr, $mEntity, TokenInterface $oToken)
  26. {
  27. $oApplication = $this->getApplication($oToken);
  28. return $mEntity->getMerchant() === $oApplication->getMerchant();
  29. }
  30. }