diff --git a/Helper/AclManager.php b/Helper/AclManager.php index c7b88dc..fcb620e 100644 --- a/Helper/AclManager.php +++ b/Helper/AclManager.php @@ -8,10 +8,12 @@ namespace Curiosity26\AclHelperBundle\Helper; +use Symfony\Component\Security\Acl\Domain\Entry; use Symfony\Component\Security\Acl\Domain\ObjectIdentity; use Symfony\Component\Security\Acl\Exception\AclNotFoundException; use Symfony\Component\Security\Acl\Model\MutableAclInterface; use Symfony\Component\Security\Acl\Model\MutableAclProviderInterface; +use Symfony\Component\Security\Acl\Model\ObjectIdentityInterface; use Symfony\Component\Security\Acl\Model\SecurityIdentityInterface; /** @@ -48,7 +50,7 @@ public function __construct(MutableAclProviderInterface $provider) */ public function aclFor($object) { - if (!$object instanceof ObjectIdentity) { + if (!$object instanceof ObjectIdentityInterface) { $object = ObjectIdentity::fromDomainObject($object); } @@ -333,6 +335,70 @@ public function save() return $this; } + /** + * @return array|Entry[] + */ + public function getClassAces(): array + { + if (null === $this->acl) { + throw new \RuntimeException("Find or create an ACL using aclFor() first."); + } + + return $this->acl->getClassAces(); + } + + /** + * @param string $field + * + * @return array|Entry[] + */ + public function getClassFieldAces(\string $field): array + { + if (null === $this->acl) { + throw new \RuntimeException("Find or create an ACL using aclFor() first."); + } + + return $this->acl->getClassFieldAces($field); + } + + /** + * @return array|Entry[] + */ + public function getObjectAces(): array + { + if (null === $this->acl) { + throw new \RuntimeException("Find or create an ACL using aclFor() first."); + } + + return $this->acl->getObjectAces(); + } + + /** + * @param string $field + * + * @return array|Entry[] + */ + public function getObjectFieldAces(\string $field): array + { + if (null === $this->acl) { + throw new \RuntimeException("Find or create an ACL using aclFor() first."); + } + + return $this->acl->getObjectFieldAces($field); + } + + /** + * @return ObjectIdentityInterface + */ + public function getObjectIdentity(): ObjectIdentityInterface + { + if (null === $this->acl) { + throw new \RuntimeException("Find or create an ACL using aclFor() first."); + } + + return $this->acl->getObjectIdentity(); + } + /** * @return null|MutableAclInterface */ @@ -344,4 +410,24 @@ public function getAcl(): ?MutableAclInterface return $this->acl; } + + /** + * Deletes the ACL + * + * @return $this + */ + public function delete() + { + if (null === $this->acl) { + throw new \RuntimeException("Find or create an ACL using aclFor() first."); + } + + $identity = $this->getObjectIdentity(); + + $this->aclProvider->deleteAcl($identity); + + $this->acl = null; + + return $this; + } }