<?php
declare(strict_types=1);
/**
* ApplicationVoter.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\Application;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* Voter for application entity
*/
class ApplicationVoter extends AbstractVoter
{
/**
* @param string $sAttribute attribute
* @param mixed $oSubject subject
* @return bool
*/
#[\Override]
public function supports($sAttribute, $oSubject)
{
return $oSubject instanceof Application && 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 UserInterface) {
return false;
}
if ($sAttr === 'DELETE' && $mEntity->getState() !== Application::STATE_NEW) {
return false;
}
if ($oUser->getUsername() == $mEntity->getMerchant()->getUsername()) {
return true;
}
return false;
}
}