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

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * ApplicationVoter.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\Application;
  27. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  28. use Symfony\Component\Security\Core\User\UserInterface;
  29. /**
  30. * Voter for application entity
  31. */
  32. class ApplicationVoter 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 Application && 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 UserInterface) {
  55. return false;
  56. }
  57. if ($sAttr === 'DELETE' && $mEntity->getState() !== Application::STATE_NEW) {
  58. return false;
  59. }
  60. if ($oUser->getUsername() == $mEntity->getMerchant()->getUsername()) {
  61. return true;
  62. }
  63. return false;
  64. }
  65. }