<?php
declare(strict_types=1);
/**
* MerchantVoter.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 :
* =========
* 20150709 - Pavel Baraulya
*
**/
namespace Bdm\BackofficeBundle\Security\Authorization\Voter;
use Bdm\BackofficeBundle\Entity\Merchant;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
/**
* Voter for merchant entity
*/
class MerchantVoter extends AbstractVoter
{
/**
* @param string $sAttribute attribute
* @param mixed $oSubject subject
* @return bool
*/
#[\Override]
public function supports($sAttribute, $oSubject)
{
return $oSubject instanceof Merchant && parent::supports($sAttribute, $oSubject);
}
/**
* Check if has access
*
* @param string $sAttr attr
* @param Merchant $oMerchant merchant
* @param TokenInterface $oToken token
*
* @return bool
*/
protected function voteOnAttribute($sAttr, $oMerchant, TokenInterface $oToken)
{
$oUser = $oToken->getUser();
if (!$oUser) {
$oUser = $this->oMerchantProvider->getUser();
}
if (!$oUser instanceof Merchant) {
return false;
}
if ($oUser->getId() == $oMerchant->getId()) {
return true;
}
return false;
}
}