for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types = 1);
/**
* /src/Security/Voter/IsUserHimselfVoter.php
*
* @author TLe, Tarmo Leppänen <[email protected]>
*/
namespace App\Security\Voter;
use App\Entity\User;
use App\Security\SecurityUser;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
* Class IsUserHimselfVoter
* @package App\Security
* @template TAttribute of string
* @template TSubject of mixed
* @extends Voter<TAttribute, TSubject>
class IsUserHimselfVoter extends Voter
{
private const ATTRIBUTE = 'IS_USER_HIMSELF';
* {@inheritdoc}
protected function supports(string $attribute, mixed $subject): bool
return $attribute === self::ATTRIBUTE && $subject instanceof User;
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
$user = $token->getUser();
return $user instanceof SecurityUser && $subject instanceof User && $user->getUuid() === $subject->getId();