Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

ValueObjectVoter.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\MVC\Symfony\Security\Authorization\Voter;
8
9 use eZ\Publish\API\Repository\Repository;
10 use eZ\Publish\Core\MVC\Symfony\Security\Authorization\Attribute as AuthorizationAttribute;
11 use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
12 use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
13
17 class ValueObjectVoter implements VoterInterface
18 {
20 private $repository;
21
22 public function __construct(Repository $repository)
23 {
24 $this->repository = $repository;
25 }
26
27 public function supportsAttribute($attribute)
28 {
29 return $attribute instanceof AuthorizationAttribute && isset($attribute->limitations['valueObject']);
30 }
31
32 public function supportsClass($class)
33 {
34 return true;
35 }
36
56 public function vote(TokenInterface $token, $object, array $attributes)
57 {
58 foreach ($attributes as $attribute) {
59 if ($this->supportsAttribute($attribute)) {
60 $targets = isset($attribute->limitations['targets']) ? $attribute->limitations['targets'] : null;
61 if (
62 $this->repository->canUser(
63 $attribute->module,
64 $attribute->function,
65 $attribute->limitations['valueObject'],
66 $targets
67 ) === false
68 ) {
69 return VoterInterface::ACCESS_DENIED;
70 }
71
72 return VoterInterface::ACCESS_GRANTED;
73 }
74 }
75
76 return VoterInterface::ACCESS_ABSTAIN;
77 }
78 }
eZ\Publish\Core\MVC\Symfony\Security\Authorization\Attribute
Authorization attribute class to be used with SecurityContextInterface::isGranted().
Definition: Attribute.php:31
eZ\Publish\Core\MVC\Symfony\Security\Authorization\Voter\ValueObjectVoter
Voter to test access to a ValueObject from Repository (e.g.
Definition: ValueObjectVoter.php:18
eZ\Publish\Core\MVC\Symfony\Security\Authorization\Voter\ValueObjectVoter\supportsAttribute
supportsAttribute($attribute)
Definition: ValueObjectVoter.php:27
eZ\Publish\Core\MVC\Symfony\Security\Authorization\Voter\ValueObjectVoter\vote
vote(TokenInterface $token, $object, array $attributes)
Returns the vote for the given parameters.
Definition: ValueObjectVoter.php:56
eZ\Publish\Core\MVC\Symfony\Security\Authorization\Voter\ValueObjectVoter\supportsClass
supportsClass($class)
Definition: ValueObjectVoter.php:32
eZ\Publish\Core\MVC\Symfony\Security\Authorization\Voter\ValueObjectVoter\$repository
$repository
Definition: ValueObjectVoter.php:20
eZ\Publish\Core\MVC\Symfony\Security\Authorization\Voter\ValueObjectVoter\__construct
__construct(Repository $repository)
Definition: ValueObjectVoter.php:22
eZ\Publish\API\Repository\Repository
Repository interface.
Definition: API/Repository/Repository.php:16
eZ\Publish\Core\MVC\Symfony\Security\Authorization\Voter
Definition: CoreVoter.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.