<?php
namespace Kobizo\Bundle\ECommerceBundle\Security\Voter;
use Kobizo\Bundle\ECommerceBundle\Entity\Store;
use Kobizo\Bundle\CoreBundle\Security\Voter\KobizoVoter;
use Kobizo\Bundle\ECommerceBundle\Resources\AccessControl\StoreResource;
class StoreVoter extends KobizoVoter
{
protected function supports($attribute, $subject): bool
{
//if role/resource is out of current voter's interest
if (!in_array($attribute, StoreResource::getAllResources())) {
return false;
}
//if it's `edit` / `delete` action, but the subject is not correct
if (!$subject instanceof Store
&& !in_array($attribute, [StoreResource::INDEX, StoreResource::CREATE])
) {
return false;
}
return true;
}
}