Symfony\Component\Security\Authorization\AccessDecisionManager::__construct PHP Méthode

__construct() public méthode

Constructor.
public __construct ( array $voters = [], string $strategy = 'affirmative', boolean $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true )
$voters array An array of VoterInterface instances
$strategy string The vote strategy
$allowIfAllAbstainDecisions boolean Whether to grant access if all voters abstained or not
    public function __construct(array $voters = array(), $strategy = 'affirmative', $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
    {
        $this->voters = $voters;
        $this->strategy = 'decide'.ucfirst($strategy);
        $this->allowIfAllAbstainDecisions = (Boolean) $allowIfAllAbstainDecisions;
        $this->allowIfEqualGrantedDeniedDecisions = (Boolean) $allowIfEqualGrantedDeniedDecisions;
    }

Usage Example

 /**
  * Constructor.
  *
  * @param VoterInterface[] $voters                     An array of VoterInterface instances
  * @param string           $strategy                   The vote strategy
  * @param Boolean          $allowIfAllAbstainDecisions Whether to grant access if all voters abstained or not
  */
 public function __construct(ContainerInterface $container, $strategy = 'affirmative', $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
 {
     parent::__construct(array(), $strategy, $allowIfAllAbstainDecisions, $allowIfEqualGrantedDeniedDecisions);
     $this->voters = array();
     foreach ($container->findTaggedServiceIds('security.voter') as $id => $attributes) {
         $this->voters[] = $container->get($id);
     }
 }