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

ParentDepthLimitationType.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\API\Repository\Values\Content\Content;
12 use eZ\Publish\API\Repository\Values\Content\ContentCreateStruct;
13 use eZ\Publish\API\Repository\Values\Content\ContentInfo;
14 use eZ\Publish\API\Repository\Values\Content\Location;
15 use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct;
16 use eZ\Publish\API\Repository\Values\Content\VersionInfo;
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\ParentDepthLimitation as APIParentDepthLimitation;
20 use eZ\Publish\API\Repository\Values\User\Limitation as APILimitationValue;
21 use eZ\Publish\SPI\Limitation\Type as SPILimitationTypeInterface;
22 use eZ\Publish\SPI\Persistence\Content\Location as SPILocation;
23
27 class ParentDepthLimitationType extends AbstractPersistenceLimitationType implements SPILimitationTypeInterface
28 {
38 public function acceptValue(APILimitationValue $limitationValue)
39 {
40 if (!$limitationValue instanceof APIParentDepthLimitation) {
41 throw new InvalidArgumentType('$limitationValue', 'APIParentDepthLimitation', $limitationValue);
42 } elseif (!is_array($limitationValue->limitationValues)) {
43 throw new InvalidArgumentType('$limitationValue->limitationValues', 'array', $limitationValue->limitationValues);
44 }
45
46 foreach ($limitationValue->limitationValues as $key => $value) {
47 // Cast integers passed as string to int
48 if (is_string($value) && ctype_digit($value)) {
49 $limitationValue->limitationValues[$key] = (int)$value;
50 } elseif (!is_int($value)) {
51 throw new InvalidArgumentType("\$limitationValue->limitationValues[{$key}]", 'int', $value);
52 }
53 }
54 }
55
65 public function validate(APILimitationValue $limitationValue)
66 {
67 $validationErrors = [];
68
69 return $validationErrors;
70 }
71
79 public function buildValue(array $limitationValues)
80 {
81 return new APIParentDepthLimitation(['limitationValues' => $limitationValues]);
82 }
83
99 public function evaluate(APILimitationValue $value, APIUserReference $currentUser, ValueObject $object, array $targets = null)
100 {
101 if (!$value instanceof APIParentDepthLimitation) {
102 throw new InvalidArgumentException('$value', 'Must be of type: APIParentDepthLimitation');
103 }
104
105 if ($object instanceof ContentCreateStruct) {
106 return $this->evaluateForContentCreateStruct($value, $targets);
107 } elseif ($object instanceof Content) {
108 $object = $object->getVersionInfo()->getContentInfo();
109 } elseif ($object instanceof VersionInfo) {
110 $object = $object->getContentInfo();
111 } elseif (!$object instanceof ContentInfo) {
112 throw new InvalidArgumentException(
113 '$object',
114 'Must be of type: ContentCreateStruct, Content, VersionInfo or ContentInfo'
115 );
116 }
117
118 // Load locations if no specific placement was provided
119 if (empty($targets)) {
120 if ($object->published) {
121 $targets = $this->persistence->locationHandler()->loadLocationsByContent($object->id);
122 } else {
123 // @todo Need support for draft locations to to work correctly
124 $targets = $this->persistence->locationHandler()->loadParentLocationsForDraftContent($object->id);
125 }
126 }
127
128 // Parent Limitations are usually used by content/create where target is specified,
129 // so we return false if not provided.
130 if (empty($targets)) {
131 return false;
132 }
133
134 foreach ($targets as $target) {
135 if ($target instanceof Location || $target instanceof SPILocation) {
136 $depth = $target->depth;
137 } else {
138 throw new InvalidArgumentException(
139 '$targets',
140 'Must contain objects of type: Location'
141 );
142 }
143
144 // All placements must match
145 if (!in_array($depth, $value->limitationValues)) {
146 return false;
147 }
148 }
149
150 return true;
151 }
152
164 protected function evaluateForContentCreateStruct(APILimitationValue $value, array $targets = null)
165 {
166 // If targets is empty/null return false as user does not have access
167 // to content w/o location with this limitation
168 if (empty($targets)) {
169 return false;
170 }
171 $hasMandatoryTarget = false;
172 foreach ($targets as $target) {
173 if ($target instanceof LocationCreateStruct) {
174 $hasMandatoryTarget = true;
175 $depth = $this->persistence->locationHandler()->load($target->parentLocationId)->depth;
176
177 // All placements must match
178 if (!in_array($depth, $value->limitationValues)) {
179 return false;
180 }
181 }
182 }
183
184 if (false === $hasMandatoryTarget) {
185 throw new InvalidArgumentException(
186 '$targets',
187 'If $object is ContentCreateStruct must contain objects of type: LocationCreateStruct'
188 );
189 }
190
191 return true;
192 }
193
202 public function getCriterion(APILimitationValue $value, APIUserReference $currentUser)
203 {
204 throw new \eZ\Publish\API\Repository\Exceptions\NotImplementedException(__METHOD__);
205 }
206
213 public function valueSchema()
214 {
215 throw new \eZ\Publish\API\Repository\Exceptions\NotImplementedException(__METHOD__);
216 }
217 }
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\LocationCreateStruct
This class is used to create a new Location for a content object.
Definition: API/Repository/Values/Content/LocationCreateStruct.php:15
eZ\Publish\API\Repository\Values\Content\Location
Definition: API/Repository/Values/Content/Location.php:32
eZ\Publish\API\Repository\Values\Content\VersionInfo
Definition: API/Repository/Values/Content/VersionInfo.php:27
eZ\Publish\API\Repository\Values\User\Limitation\ParentDepthLimitation
Definition: ParentDepthLimitation.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\Limitation\AbstractPersistenceLimitationType
LocationLimitation is a Content limitation.
Definition: AbstractPersistenceLimitationType.php:15
eZ\Publish\Core\Limitation\ParentDepthLimitationType
ParentDepthLimitation is a Content limitation.
Definition: ParentDepthLimitationType.php:28
eZ\Publish\Core\Limitation\ParentDepthLimitationType\valueSchema
valueSchema()
Returns info on valid $limitationValues.
Definition: ParentDepthLimitationType.php:213
eZ\Publish\Core\Limitation\ParentDepthLimitationType\getCriterion
getCriterion(APILimitationValue $value, APIUserReference $currentUser)
Returns Criterion for use in find() query.
Definition: ParentDepthLimitationType.php:202
eZ\Publish\Core\Limitation\ParentDepthLimitationType\buildValue
buildValue(array $limitationValues)
Create the Limitation Value.
Definition: ParentDepthLimitationType.php:79
eZ\Publish\Core\Limitation\ParentDepthLimitationType\evaluateForContentCreateStruct
evaluateForContentCreateStruct(APILimitationValue $value, array $targets=null)
Evaluate permissions for ContentCreateStruct against LocationCreateStruct placements.
Definition: ParentDepthLimitationType.php:164
eZ\Publish\Core\Limitation\ParentDepthLimitationType\evaluate
evaluate(APILimitationValue $value, APIUserReference $currentUser, ValueObject $object, array $targets=null)
Evaluate permission against content & target(placement/parent/assignment).
Definition: ParentDepthLimitationType.php:99
eZ\Publish\Core\Limitation\ParentDepthLimitationType\acceptValue
acceptValue(APILimitationValue $limitationValue)
Accepts a Limitation value and checks for structural validity.
Definition: ParentDepthLimitationType.php:38
eZ\Publish\Core\Limitation\ParentDepthLimitationType\validate
validate(APILimitationValue $limitationValue)
Makes sure LimitationValue->limitationValues is valid according to valueSchema().
Definition: ParentDepthLimitationType.php:65
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
eZ\Publish\SPI\Persistence\Content\Location
Definition: SPI/Persistence/Content/Location/CreateStruct.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.