<?php
declare(strict_types=1);
namespace App\Platform\Security;
use App\Bundles\UserBundle\Entity\User;
use LogicException;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class DashboardVoter extends Voter
{
public const ENTITY_TYPE_VIEW = 'entity_type_view';
protected function supports(string $attribute, $subject): bool
{
// if the attribute isn't one we support, return false
if (!in_array($attribute, [self::ENTITY_TYPE_VIEW])) {
return false;
}
// // only vote on `SavedSearch` objects
// if (!$subject instanceof SavedSearch) {
// return false;
// }
return true;
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
$user = $token->getUser();
if (!$user instanceof User) {
// the user must be logged in; if not, deny access
return false;
}
// you know $subject is a SavedSearch object, thanks to `supports()`
// /** @var SavedSearch $savedSearch */
// $savedSearch = $subject;
switch ($attribute) {
case self::ENTITY_TYPE_VIEW:
return $this->canView($subject, $user);
}
throw new LogicException('This code should not be reached!');
}
private function canView(mixed $subject, User $user): bool
{
// TODO: Implement canView() method.
return false;
}
}