Skip to content

Commit

Permalink
Use trait
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Feb 14, 2024
1 parent 4f067d9 commit e6d4a47
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions Voter/AclVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,39 @@
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;

if (class_exists(\Symfony\Component\Security\Core\Security::class)) {
/**
* @internal
*/
trait AclVoterTrait
{
public function vote(TokenInterface $token, $subject, array $attributes)
{
return $this->internalVote($token, $subject, $attributes);
}
}
} else {
/**
* @internal
*/
trait AclVoterTrait
{
public function vote(TokenInterface $token, mixed $subject, array $attributes): int
{
return $this->internalVote($token, $subject, $attributes);
}
}
}

/**
* This voter can be used as a base class for implementing your own permissions.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*
* @internal
*/
abstract class InternalAclVoter implements VoterInterface
class AclVoter implements VoterInterface
{
use AclVoterTrait;

private $aclProvider;
private $permissionMap;
private $objectIdentityRetrievalStrategy;
Expand All @@ -53,10 +77,7 @@ public function supportsAttribute($attribute)
return \is_string($attribute) && $this->permissionMap->contains($attribute);
}

/**
* @internal
*/
protected function internalVote(TokenInterface $token, $subject, array $attributes)
private function internalVote(TokenInterface $token, $subject, array $attributes)
{
foreach ($attributes as $attribute) {
if (!$this->supportsAttribute($attribute)) {
Expand Down Expand Up @@ -150,21 +171,3 @@ public function supportsClass($class)
return true;
}
}

if (class_exists(\Symfony\Component\Security\Core\Security::class)) {
class AclVoter extends InternalAclVoter
{
public function vote(TokenInterface $token, $subject, array $attributes)
{
return $this->internalVote($token, $subject, $attributes);
}
}
} else {
class AclVoter extends InternalAclVoter
{
public function vote(TokenInterface $token, mixed $subject, array $attributes): int
{
return $this->internalVote($token, $subject, $attributes);
}
}
}

0 comments on commit e6d4a47

Please sign in to comment.