<?php
declare(strict_types=1);
namespace Bdm\PublicApiBundle\Security\Authorization\Voter;
use Bdm\BackofficeBundle\Entity\MerchantAwareInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use function is_object;
class MerchantOwnerVoter extends AbstractVoter
{
/**
* @param string $sAttribute attribute
* @param mixed $oSubject subject
* @return bool
*/
public function supports($sAttribute, $oSubject)
{
return is_object($oSubject) && $oSubject instanceof MerchantAwareInterface;
}
/**
* @param string $sAttr attr
* @param mixed $mEntity entity
* @param TokenInterface $oToken token
*
* @return bool
*/
protected function voteOnAttribute($sAttr, $mEntity, TokenInterface $oToken)
{
$oApplication = $this->getApplication($oToken);
return $mEntity->getMerchant() === $oApplication->getMerchant();
}
}