<?php
declare(strict_types=1);
/**
* PayoutVoter.php File.
* This file is part of the Payment.net Project.
*
* PHP version 5
*
* @category Application
* @package Bdm\BackofficeBundle\Security\Authorization\Voter
* @author Pavel Baraulya <pbaraulya@bdmultimedia.fr>
* @link http://www.payment.net/
*
* FEATURES :
* ==========
*
* TODO-LIST :
* ===========
*
* HISTORY :
* =========
* 20150715 - Pavel Baraulya
*
**/
namespace Bdm\BackofficeBundle\Security\Authorization\Voter;
use Bdm\BackofficeBundle\Entity\Merchant;
use Bdm\BackofficeBundle\Entity\Payout;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
/**
* Voter for payout entity
*/
class PayoutVoter extends AbstractVoter
{
/**
* @param string $sAttribute attribute
* @param mixed $oSubject subject
* @return bool
*/
#[\Override]
public function supports($sAttribute, $oSubject)
{
return $oSubject instanceof Payout && parent::supports($sAttribute, $oSubject);
}
/**
* @param string $sAttr attr
* @param mixed $mEntity entity
* @param TokenInterface $oToken token
*
* @return bool
*/
protected function voteOnAttribute($sAttr, $mEntity, TokenInterface $oToken)
{
$oUser = $oToken->getUser();
if (!$oUser instanceof Merchant) {
return false;
}
if ($mEntity->getMerchant()->getId() == $oUser->getId()) {
return true;
}
return false;
}
}