src/Security/DisableAccessControlVoter.php line 6

Open in your IDE?
  1. <?php
  2. namespace App\Security;
  3. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  4. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  5. class DisableAccessControlVoter extends Voter
  6. {
  7.     // Not using This Class ðŸ’¡ðŸ’¡ðŸ’¡ðŸ’¡ðŸ’¡ðŸ’¡ðŸ’¡ðŸ’¡ðŸ’¡ðŸ’¡
  8.     /**
  9.      * Determines if the attribute and subject are supported by this voter.
  10.      *
  11.      * @param string $attribute An attribute
  12.      * @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type
  13.      *
  14.      * @return bool
  15.      */
  16.     protected function supports($attribute$subject)
  17.     {
  18.         // Check if this voter supports the given attribute
  19.         return 'DISABLE_ACCESS_CONTROL' === $attribute;
  20.     }
  21.     /**
  22.      * Perform a single access check operation on a given attribute, subject and token.
  23.      * It is safe to assume that $attribute and $subject already passed the "supports()" method check.
  24.      *
  25.      * @param $attribute
  26.      * @param mixed $subject
  27.      *
  28.      * @param TokenInterface $token
  29.      * @return bool
  30.      */
  31.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  32.     {
  33.         // Check for the specific parameter here
  34.         $request $token->getAttribute('request');
  35.         if ($request && $request->query->get('disable_access_control') === 'true') {
  36.             return true// Grant access if the parameter is present
  37.         }
  38.         return false// Deny access by default
  39.     }
  40. }