<?php
namespace App\Security;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class DisableAccessControlVoter extends Voter
{
// Not using This Class 💡💡💡💡💡💡💡💡💡💡
/**
* Determines if the attribute and subject are supported by this voter.
*
* @param string $attribute An attribute
* @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type
*
* @return bool
*/
protected function supports($attribute, $subject)
{
// Check if this voter supports the given attribute
return 'DISABLE_ACCESS_CONTROL' === $attribute;
}
/**
* Perform a single access check operation on a given attribute, subject and token.
* It is safe to assume that $attribute and $subject already passed the "supports()" method check.
*
* @param $attribute
* @param mixed $subject
*
* @param TokenInterface $token
* @return bool
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
// Check for the specific parameter here
$request = $token->getAttribute('request');
if ($request && $request->query->get('disable_access_control') === 'true') {
return true; // Grant access if the parameter is present
}
return false; // Deny access by default
}
}