bundles/BackofficeBundle/Security/Authorization/Voter/MerchantVoter.php line 35

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * MerchantVoter.php File.
  5. * This file is part of the Payment.net Project.
  6. *
  7. * PHP version 5
  8. *
  9. * @category Application
  10. * @package Bdm\BackofficeBundle\Security\Authorization\Voter
  11. * @author Pavel Baraulya <pbaraulya@bdmultimedia.fr>
  12. * @link http://www.payment.net/
  13. *
  14. * FEATURES :
  15. * ==========
  16. *
  17. * TODO-LIST :
  18. * ===========
  19. *
  20. * HISTORY :
  21. * =========
  22. * 20150709 - Pavel Baraulya
  23. *
  24. **/
  25. namespace Bdm\BackofficeBundle\Security\Authorization\Voter;
  26. use Bdm\BackofficeBundle\Entity\Merchant;
  27. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  28. /**
  29. * Voter for merchant entity
  30. */
  31. class MerchantVoter extends AbstractVoter
  32. {
  33. /**
  34. * @param string $sAttribute attribute
  35. * @param mixed $oSubject subject
  36. * @return bool
  37. */
  38. #[\Override]
  39. public function supports($sAttribute, $oSubject)
  40. {
  41. return $oSubject instanceof Merchant && parent::supports($sAttribute, $oSubject);
  42. }
  43. /**
  44. * Check if has access
  45. *
  46. * @param string $sAttr attr
  47. * @param Merchant $oMerchant merchant
  48. * @param TokenInterface $oToken token
  49. *
  50. * @return bool
  51. */
  52. protected function voteOnAttribute($sAttr, $oMerchant, TokenInterface $oToken)
  53. {
  54. $oUser = $oToken->getUser();
  55. if (!$oUser) {
  56. $oUser = $this->oMerchantProvider->getUser();
  57. }
  58. if (!$oUser instanceof Merchant) {
  59. return false;
  60. }
  61. if ($oUser->getId() == $oMerchant->getId()) {
  62. return true;
  63. }
  64. return false;
  65. }
  66. }