<?php
namespace WAM\Bundle\EcommerceBundle\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use WAM\Bundle\EcommerceBundle\Entity\Interfaces\AddressInterface;
/**
* @author Juanjo MartÃnez <jmartinez@wearemarketing.com>
*/
class AddressVoter extends Voter
{
const EDIT = 'EDIT';
const DELETE = 'DELETE';
protected function supports($attribute, $subject)
{
if (!in_array($attribute, [self::EDIT, self::DELETE])) {
return false;
}
if (!$subject instanceof AddressInterface) {
return false;
}
return true;
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
return $token->getUser() == $subject->getCustomer();
}
}