bundles/BackofficeBundle/Security/Authorization/Voter/PayoutVoter.php line 36

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * PayoutVoter.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. * 20150715 - Pavel Baraulya
  23. *
  24. **/
  25. namespace Bdm\BackofficeBundle\Security\Authorization\Voter;
  26. use Bdm\BackofficeBundle\Entity\Merchant;
  27. use Bdm\BackofficeBundle\Entity\Payout;
  28. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  29. /**
  30. * Voter for payout entity
  31. */
  32. class PayoutVoter extends AbstractVoter
  33. {
  34. /**
  35. * @param string $sAttribute attribute
  36. * @param mixed $oSubject subject
  37. * @return bool
  38. */
  39. #[\Override]
  40. public function supports($sAttribute, $oSubject)
  41. {
  42. return $oSubject instanceof Payout && parent::supports($sAttribute, $oSubject);
  43. }
  44. /**
  45. * @param string $sAttr attr
  46. * @param mixed $mEntity entity
  47. * @param TokenInterface $oToken token
  48. *
  49. * @return bool
  50. */
  51. protected function voteOnAttribute($sAttr, $mEntity, TokenInterface $oToken)
  52. {
  53. $oUser = $oToken->getUser();
  54. if (!$oUser instanceof Merchant) {
  55. return false;
  56. }
  57. if ($mEntity->getMerchant()->getId() == $oUser->getId()) {
  58. return true;
  59. }
  60. return false;
  61. }
  62. }