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

SectionLimitationType.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Limitation;
8
9 use eZ\Publish\API\Repository\Exceptions\NotFoundException as APINotFoundException;
10 use eZ\Publish\API\Repository\Values\ValueObject;
11 use eZ\Publish\API\Repository\Values\User\UserReference as APIUserReference;
12 use eZ\Publish\API\Repository\Values\Content\Content;
13 use eZ\Publish\API\Repository\Values\Content\ContentInfo;
14 use eZ\Publish\API\Repository\Values\Content\ContentCreateStruct;
15 use eZ\Publish\API\Repository\Values\Content\VersionInfo;
16 use eZ\Publish\API\Repository\Values\Content\Section;
17 use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException;
18 use eZ\Publish\Core\Base\Exceptions\InvalidArgumentType;
19 use eZ\Publish\API\Repository\Values\User\Limitation\SectionLimitation as APISectionLimitation;
20 use eZ\Publish\API\Repository\Values\User\Limitation as APILimitationValue;
21 use eZ\Publish\SPI\Limitation\Type as SPILimitationTypeInterface;
22 use eZ\Publish\Core\FieldType\ValidationError;
23 use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
24
28 class SectionLimitationType extends AbstractPersistenceLimitationType implements SPILimitationTypeInterface
29 {
39 public function acceptValue(APILimitationValue $limitationValue)
40 {
41 if (!$limitationValue instanceof APISectionLimitation) {
42 throw new InvalidArgumentType('$limitationValue', 'APISectionLimitation', $limitationValue);
43 } elseif (!is_array($limitationValue->limitationValues)) {
44 throw new InvalidArgumentType('$limitationValue->limitationValues', 'array', $limitationValue->limitationValues);
45 }
46
47 foreach ($limitationValue->limitationValues as $key => $id) {
48 if (!is_string($id) && !is_int($id)) {
49 throw new InvalidArgumentType("\$limitationValue->limitationValues[{$key}]", 'int|string', $id);
50 }
51 }
52 }
53
63 public function validate(APILimitationValue $limitationValue)
64 {
65 $validationErrors = [];
66 foreach ($limitationValue->limitationValues as $key => $id) {
67 try {
68 $this->persistence->sectionHandler()->load($id);
69 } catch (APINotFoundException $e) {
70 $validationErrors[] = new ValidationError(
71 "limitationValues[%key%] => '%value%' does not exist in the backend",
72 null,
73 [
74 'value' => $id,
75 'key' => $key,
76 ]
77 );
78 }
79 }
80
81 return $validationErrors;
82 }
83
91 public function buildValue(array $limitationValues)
92 {
93 return new APISectionLimitation(['limitationValues' => $limitationValues]);
94 }
95
111 public function evaluate(APILimitationValue $value, APIUserReference $currentUser, ValueObject $object, array $targets = null)
112 {
113 if (!$value instanceof APISectionLimitation) {
114 throw new InvalidArgumentException('$value', 'Must be of type: APISectionLimitation');
115 }
116
117 if (empty($value->limitationValues)) {
118 return false;
119 }
120
126 if ($object instanceof Section) {
127 return in_array($object->id, $value->limitationValues);
128 } elseif ($object instanceof Content) {
129 $object = $object->getVersionInfo()->getContentInfo();
130 } elseif ($object instanceof VersionInfo) {
131 $object = $object->getContentInfo();
132 } elseif (!$object instanceof ContentInfo && !$object instanceof ContentCreateStruct) {
133 // As this is Role limitation we need to signal abstain on unsupported $object
134 return self::ACCESS_ABSTAIN;
135 }
136
137 /*
138 * We ignore Targets here, they are only interesting in NewState limitation as we on this one is more interested
139 * the section already assigned to object.
140 *
141 * @var $object ContentInfo|ContentCreateStruct
142 */
143 return in_array($object->sectionId, $value->limitationValues);
144 }
145
154 public function getCriterion(APILimitationValue $value, APIUserReference $currentUser)
155 {
156 if (empty($value->limitationValues)) {
157 // no limitation values
158 throw new \RuntimeException('$value->limitationValues is empty, it should not have been stored in the first place');
159 }
160
161 if (!isset($value->limitationValues[1])) {
162 // 1 limitation value: EQ operation
163 return new Criterion\SectionId($value->limitationValues[0]);
164 }
165
166 // several limitation values: IN operation
167 return new Criterion\SectionId($value->limitationValues);
168 }
169
176 public function valueSchema()
177 {
178 throw new \eZ\Publish\API\Repository\Exceptions\NotImplementedException(__METHOD__);
179 }
180 }
eZ\Publish\API\Repository\Exceptions\NotFoundException
This Exception is thrown if an object referenced by an id or identifier could not be found in the rep...
Definition: API/Repository/Exceptions/NotFoundException.php:16
eZ\Publish\API\Repository\Values\Content\ContentCreateStruct
Definition: API/Repository/Values/Content/ContentCreateStruct.php:15
eZ\Publish\API\Repository\Values\Content\ContentInfo
Definition: API/Repository/Values/Content/ContentInfo.php:31
eZ\Publish\API\Repository\Values\Content\Content
Definition: Publish/API/Repository/Values/Content/Content.php:21
eZ\Publish\API\Repository\Values\Content\Section
Definition: API/Repository/Values/Content/Section.php:19
eZ\Publish\API\Repository\Values\Content\VersionInfo
Definition: API/Repository/Values/Content/VersionInfo.php:27
eZ\Publish\API\Repository\Values\User\Limitation\SectionLimitation
Definition: SectionLimitation.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\AbstractPersistenceLimitationType
LocationLimitation is a Content limitation.
Definition: AbstractPersistenceLimitationType.php:15
eZ\Publish\Core\Limitation\SectionLimitationType
SectionLimitation is a Content Limitation & a Role Limitation.
Definition: SectionLimitationType.php:29
eZ\Publish\Core\Limitation\SectionLimitationType\evaluate
evaluate(APILimitationValue $value, APIUserReference $currentUser, ValueObject $object, array $targets=null)
Evaluate permission against content & target(placement/parent/assignment).
Definition: SectionLimitationType.php:111
eZ\Publish\Core\Limitation\SectionLimitationType\valueSchema
valueSchema()
Returns info on valid $limitationValues.
Definition: SectionLimitationType.php:176
eZ\Publish\Core\Limitation\SectionLimitationType\buildValue
buildValue(array $limitationValues)
Create the Limitation Value.
Definition: SectionLimitationType.php:91
eZ\Publish\Core\Limitation\SectionLimitationType\getCriterion
getCriterion(APILimitationValue $value, APIUserReference $currentUser)
Returns Criterion for use in find() query.
Definition: SectionLimitationType.php:154
eZ\Publish\Core\Limitation\SectionLimitationType\acceptValue
acceptValue(APILimitationValue $limitationValue)
Accepts a Limitation value and checks for structural validity.
Definition: SectionLimitationType.php:39
eZ\Publish\Core\Limitation\SectionLimitationType\validate
validate(APILimitationValue $limitationValue)
Makes sure LimitationValue->limitationValues is valid according to valueSchema().
Definition: SectionLimitationType.php:63
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\SPI\Limitation\Type\ACCESS_ABSTAIN
const ACCESS_ABSTAIN
Definition: SPI/Limitation/Type.php:34
eZ\Publish\API\Repository\Values\Content\Query\Criterion
Definition: API/Repository/Values/Content/Query/Criterion/Ancestor.php:7
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+.