<?php
namespace App\Security\Voter\ObjectManagement;
use App\Daikin\BaseBundle\Entity\Objects;
use App\Security\Voter\SubjectCompanyOwnerVoterTrait;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class ObjectsVoter extends Voter
{
use SubjectCompanyOwnerVoterTrait;
protected function supports(string $attribute, $subject): bool
{
return $subject instanceof Objects;
}
public function supportsAttribute(string $attribute): bool
{
return $attribute === 'CRUD';
}
public function supportsType(string $subjectType): bool
{
return is_a($subjectType, Objects::class, true);
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
return $this->companyOwnsSubject($token->getUser(), $subject);
}
}