Skip to content

Commit

Permalink
Add delete capabilitt for ACL Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
curiosity26 committed Nov 5, 2018
1 parent a647685 commit 3c8b730
Showing 1 changed file with 87 additions and 1 deletion.
88 changes: 87 additions & 1 deletion Helper/AclManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
*/
Expand All @@ -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;
}
}

0 comments on commit 3c8b730

Please sign in to comment.