Symfony ACL:updateObjectAce() 索引错误

Symfony ACL: updateObjectAce() Indexing Errors

我在 Symfony 服务中有以下功能,它应该为给定用户更新实体的 ACL:

public function editPermission($user, $entity){
    $allEntities = $this->em->getRepository($entity)->findAll();

    /**
     * ACLs grant user permission on every instance of each entity.
     * In order to edit permissions across all of these entites for each user,
     * first iterate over all entities. 
     * For each entity, update the permission for the specified user.
     */
    foreach($allEntities as $oneEntity){
      // locate the ACL
      $objectIdentity = ObjectIdentity::fromDomainObject($oneEntity);
      $acl = $this->aclProvider->findAcl($objectIdentity);

      // update user access
      $entityId = $objectIdentity->getIdentifier();

      $objectAces = $acl->getObjectAces();
      for ($i=(sizeof($objectAces)-1); $i>=0; $i--){
          $acl->updateObjectAce($objectAces[$i], MaskBuilder::MASK_DELETE); 
      }
      $this->aclProvider->updateAcl($acl);
    }

    return true;
  }   

目前我的 'acl_entries' table 中只有两个条目。在遍历 $objectAces 时,我收到通知:

Notice: Undefined offset: 0

现在,假设我将我的 updateObjectAce 索引更改为“1”而不是 $objectAces[$i]。当我这样做时,第一条记录的掩码更新,但我收到错误:

The index "1" does not exist.

如果我将 updateObjectAce 索引更改为“2”,则第二条记录不会更新并且出现错误:

The index "2" does not exist.

ACL 是否有一些我在这里遗漏的奇怪的更新方式?

似乎与 this comment and fix in this manner 中描述的情况相同。 试试这个:

$objectAces = $acl->getObjectAces();
foreach($aces as $i => $ace) {
          $acl->updateObjectAce($i, MaskBuilder::MASK_DELETE); 
      }

而不是这个:

$objectAces = $acl->getObjectAces();
for ($i=(sizeof($objectAces)-1); $i>=0; $i--){
          $acl->updateObjectAce($objectAces[$i], MaskBuilder::MASK_DELETE); 
      }

希望对您有所帮助