vendor/kunstmaan/admin-bundle/Helper/Security/Acl/Voter/AclVoter.php line 27

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Kunstmaan\AdminBundle\Helper\Security\Acl\Voter;
  11. use Psr\Log\LoggerInterface;
  12. use Symfony\Component\Security\Acl\Model\AclProviderInterface;
  13. use Symfony\Component\Security\Acl\Model\ObjectIdentityRetrievalStrategyInterface;
  14. use Symfony\Component\Security\Acl\Model\SecurityIdentityRetrievalStrategyInterface;
  15. use Symfony\Component\Security\Acl\Permission\PermissionMapInterface;
  16. use Symfony\Component\Security\Acl\Voter\AclVoter as BaseAclVoter;
  17. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  18. /**
  19.  * This voter can be used as a base class for implementing your own permissions.
  20.  *
  21.  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  22.  */
  23. class AclVoter extends BaseAclVoter
  24. {
  25.     /** @var bool */
  26.     private $permissionsEnabled;
  27.     public function __construct(AclProviderInterface $aclProviderObjectIdentityRetrievalStrategyInterface $oidRetrievalStrategySecurityIdentityRetrievalStrategyInterface $sidRetrievalStrategyPermissionMapInterface $permissionMapLoggerInterface $logger null$allowIfObjectIdentityUnavailable true$permissionsEnabled true)
  28.     {
  29.         parent::__construct($aclProvider$oidRetrievalStrategy$sidRetrievalStrategy$permissionMap$logger$allowIfObjectIdentityUnavailable);
  30.         $this->permissionsEnabled $permissionsEnabled;
  31.     }
  32.     public function vote(TokenInterface $token$object, array $attributes)
  33.     {
  34.         $attributeIsSupported false;
  35.         foreach ($attributes as $attribute) {
  36.             if ($this->supportsAttribute($attribute)) {
  37.                 $attributeIsSupported true;
  38.                 break;
  39.             }
  40.         }
  41.         if (!$this->permissionsEnabled && $attributeIsSupported) {
  42.             return self::ACCESS_GRANTED;
  43.         }
  44.         if (!$this->permissionsEnabled) {
  45.             return self::ACCESS_ABSTAIN;
  46.         }
  47.         return parent::vote($token$object$attributes);
  48.     }
  49. }