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

SiteAccessLimitationType.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Limitation;
8
9 use eZ\Publish\API\Repository\Values\ValueObject;
10 use eZ\Publish\API\Repository\Values\User\UserReference as APIUserReference;
11 use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException;
12 use eZ\Publish\Core\Base\Exceptions\InvalidArgumentType;
13 use eZ\Publish\API\Repository\Values\User\Limitation\SiteAccessLimitation as APISiteAccessLimitation;
14 use eZ\Publish\API\Repository\Values\User\Limitation as APILimitationValue;
15 use eZ\Publish\Core\FieldType\ValidationError;
16 use eZ\Publish\Core\MVC\Symfony\SiteAccess;
17 use eZ\Publish\SPI\Limitation\Type as SPILimitationTypeInterface;
18
22 class SiteAccessLimitationType implements SPILimitationTypeInterface
23 {
25 private $siteAccessList = [];
26
27 public function __construct(array $siteAccessList = [])
28 {
29 foreach ($siteAccessList as $sa) {
30 $this->siteAccessList[$this->generateSiteAccessValue($sa)] = $sa;
31 }
32 }
33
41 private function generateSiteAccessValue($sa)
42 {
43 return sprintf('%u', crc32($sa));
44 }
45
55 public function acceptValue(APILimitationValue $limitationValue)
56 {
57 if (!$limitationValue instanceof APISiteAccessLimitation) {
58 throw new InvalidArgumentType('$limitationValue', 'APISiteAccessLimitation', $limitationValue);
59 } elseif (!is_array($limitationValue->limitationValues)) {
60 throw new InvalidArgumentType('$limitationValue->limitationValues', 'array', $limitationValue->limitationValues);
61 }
62
63 foreach ($limitationValue->limitationValues as $key => $value) {
64 // Value must be a CRC32, so can be either as string or integer.
65 if (!is_string($value) && !is_int($value)) {
66 throw new InvalidArgumentType("\$limitationValue->limitationValues[{$key}]", 'string or integer', $value);
67 }
68 }
69 }
70
80 public function validate(APILimitationValue $limitationValue)
81 {
82 $validationErrors = [];
83 foreach ($limitationValue->limitationValues as $key => $value) {
84 if (!isset($this->siteAccessList[$value])) {
85 $validationErrors[] = new ValidationError(
86 "\$limitationValue->limitationValues[%key%] => Invalid SiteAccess value \"$value\"",
87 null,
88 [
89 'value' => $value,
90 'key' => $key,
91 ]
92 );
93 }
94 }
95
96 return $validationErrors;
97 }
98
106 public function buildValue(array $limitationValues)
107 {
108 return new APISiteAccessLimitation(['limitationValues' => $limitationValues]);
109 }
110
129 public function evaluate(APILimitationValue $value, APIUserReference $currentUser, ValueObject $object, array $targets = null)
130 {
131 if (!$value instanceof APISiteAccessLimitation) {
132 throw new InvalidArgumentException('$value', 'Must be of type: APISiteAccessLimitation');
133 }
134
135 if (!$object instanceof SiteAccess) {
136 throw new InvalidArgumentException('$object', 'Must be of type: SiteAccess');
137 }
138
139 if (empty($value->limitationValues)) {
140 return false;
141 }
142
143 if (empty($object->name)) {
144 return false;
145 }
146
147 $currentSiteAccessHash = $this->generateSiteAccessValue($object->name);
148
149 return in_array($currentSiteAccessHash, $value->limitationValues);
150 }
151
160 public function getCriterion(APILimitationValue $value, APIUserReference $currentUser)
161 {
162 throw new \eZ\Publish\API\Repository\Exceptions\NotImplementedException(__METHOD__);
163 }
164
171 public function valueSchema()
172 {
173 throw new \eZ\Publish\API\Repository\Exceptions\NotImplementedException(__METHOD__);
174 }
175 }
eZ\Publish\API\Repository\Values\User\Limitation\SiteAccessLimitation
Definition: SiteAccessLimitation.php:12
eZ\Publish\API\Repository\Values\ValueObject
Definition: API/Repository/Values/ValueObject.php:21
eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
Invalid Argument Type Exception implementation.
Definition: Core/Base/Exceptions/InvalidArgumentException.php:20
eZ\Publish\Core\Base\Exceptions\InvalidArgumentType
Invalid Argument Type Exception implementation.
Definition: InvalidArgumentType.php:17
eZ\Publish\Core\FieldType\ValidationError
Class for validation errors.
Definition: Core/FieldType/ValidationError.php:17
eZ\Publish\Core\Limitation\SiteAccessLimitationType
SiteAccessLimitation is a User limitation.
Definition: SiteAccessLimitationType.php:23
eZ\Publish\Core\Limitation\SiteAccessLimitationType\acceptValue
acceptValue(APILimitationValue $limitationValue)
Accepts a Limitation value and checks for structural validity.
Definition: SiteAccessLimitationType.php:55
eZ\Publish\Core\Limitation\SiteAccessLimitationType\buildValue
buildValue(array $limitationValues)
Create the Limitation Value.
Definition: SiteAccessLimitationType.php:106
eZ\Publish\Core\Limitation\SiteAccessLimitationType\generateSiteAccessValue
generateSiteAccessValue($sa)
Generates the SiteAccess value as CRC32.
Definition: SiteAccessLimitationType.php:41
eZ\Publish\Core\Limitation\SiteAccessLimitationType\__construct
__construct(array $siteAccessList=[])
Definition: SiteAccessLimitationType.php:27
eZ\Publish\Core\Limitation\SiteAccessLimitationType\valueSchema
valueSchema()
Returns info on valid $limitationValues.
Definition: SiteAccessLimitationType.php:171
eZ\Publish\Core\Limitation\SiteAccessLimitationType\validate
validate(APILimitationValue $limitationValue)
Makes sure LimitationValue->limitationValues is valid according to valueSchema().
Definition: SiteAccessLimitationType.php:80
eZ\Publish\Core\Limitation\SiteAccessLimitationType\$siteAccessList
$siteAccessList
Definition: SiteAccessLimitationType.php:25
eZ\Publish\Core\Limitation\SiteAccessLimitationType\evaluate
evaluate(APILimitationValue $value, APIUserReference $currentUser, ValueObject $object, array $targets=null)
Evaluate permission against content & target(placement/parent/assignment).
Definition: SiteAccessLimitationType.php:129
eZ\Publish\Core\Limitation\SiteAccessLimitationType\getCriterion
getCriterion(APILimitationValue $value, APIUserReference $currentUser)
Returns Criterion for use in find() query.
Definition: SiteAccessLimitationType.php:160
eZ\Publish\Core\MVC\Symfony\SiteAccess
Base struct for a siteaccess representation.
Definition: SiteAccess.php:16
eZ\Publish\API\Repository\Values\User\UserReference
This interface represents a user reference for use in sessions and Repository.
Definition: API/Repository/Values/User/UserReference.php:13
eZ\Publish\SPI\Limitation\Type
This interface represent the Limitation Type.
Definition: SPI/Limitation/Type.php:22
eZ\Publish\API\Repository\Values\User\Limitation
Definition: BlockingLimitation.php:7
eZ\Publish\Core\Limitation
Definition: AbstractPersistenceLimitationType.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.