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

NewObjectStateLimitationType.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\Exceptions\NotImplementedException;
11 use eZ\Publish\API\Repository\Values\ValueObject;
12 use eZ\Publish\API\Repository\Values\User\UserReference as APIUserReference;
13 use eZ\Publish\API\Repository\Values\Content\Content;
14 use eZ\Publish\API\Repository\Values\Content\ContentInfo;
15 use eZ\Publish\API\Repository\Values\ObjectState\ObjectState;
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\NewObjectStateLimitation as APINewObjectStateLimitation;
20 use eZ\Publish\API\Repository\Values\User\Limitation as APILimitationValue;
21 use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
22 use eZ\Publish\SPI\Limitation\Type as SPILimitationTypeInterface;
23 use eZ\Publish\SPI\Persistence\Content\ObjectState as SPIObjectState;
24 use eZ\Publish\Core\FieldType\ValidationError;
25
29 class NewObjectStateLimitationType extends AbstractPersistenceLimitationType implements SPILimitationTypeInterface
30 {
40 public function acceptValue(APILimitationValue $limitationValue)
41 {
42 if (!$limitationValue instanceof APINewObjectStateLimitation) {
43 throw new InvalidArgumentType('$limitationValue', 'NewObjectStateLimitation', $limitationValue);
44 } elseif (!is_array($limitationValue->limitationValues)) {
45 throw new InvalidArgumentType('$limitationValue->limitationValues', 'array', $limitationValue->limitationValues);
46 }
47
48 foreach ($limitationValue->limitationValues as $key => $id) {
49 if (!is_string($id) && !is_int($id)) {
50 throw new InvalidArgumentType("\$limitationValue->limitationValues[{$key}]", 'int|string', $id);
51 }
52 }
53 }
54
64 public function validate(APILimitationValue $limitationValue)
65 {
66 $validationErrors = [];
67 foreach ($limitationValue->limitationValues as $key => $id) {
68 try {
69 $this->persistence->objectStateHandler()->load($id);
70 } catch (APINotFoundException $e) {
71 $validationErrors[] = new ValidationError(
72 "limitationValues[%key%] => '%value%' does not exist in the backend",
73 null,
74 [
75 'value' => $id,
76 'key' => $key,
77 ]
78 );
79 }
80 }
81
82 return $validationErrors;
83 }
84
92 public function buildValue(array $limitationValues)
93 {
94 return new APINewObjectStateLimitation(['limitationValues' => $limitationValues]);
95 }
96
112 public function evaluate(APILimitationValue $value, APIUserReference $currentUser, ValueObject $object, array $targets = null)
113 {
114 if (!$value instanceof APINewObjectStateLimitation) {
115 throw new InvalidArgumentException('$value', 'Must be of type: NewObjectStateLimitation');
116 }
117
118 if (!$object instanceof ContentInfo && !$object instanceof Content && !$object instanceof VersionInfo) {
119 throw new InvalidArgumentException('$object', 'Must be of type: Content, VersionInfo or ContentInfo');
120 }
121
122 if (empty($targets)) {
123 throw new InvalidArgumentException('$targets', 'Must contain objects of type: ObjectState');
124 }
125
126 if (empty($value->limitationValues)) {
127 return false;
128 }
129
130 foreach ($targets as $target) {
131 if (!$target instanceof ObjectState && !$target instanceof SPIObjectState) {
132 throw new InvalidArgumentException('$targets', 'Must contain objects of type: ObjectState');
133 }
134
135 if (!in_array($target->id, $value->limitationValues)) {
136 return false;
137 }
138 }
139
140 return true;
141 }
142
153 public function getCriterion(APILimitationValue $value, APIUserReference $currentUser)
154 {
155 throw new NotImplementedException(__METHOD__);
156 }
157
164 public function valueSchema()
165 {
166 throw new NotImplementedException(__METHOD__);
167 }
168 }
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\Exceptions\NotImplementedException
This Exception is thrown if a feature has not been implemented intentionally.
Definition: API/Repository/Exceptions/NotImplementedException.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\VersionInfo
Definition: API/Repository/Values/Content/VersionInfo.php:27
eZ\Publish\API\Repository\Values\ObjectState\ObjectState
Definition: API/Repository/Values/ObjectState/ObjectState.php:23
eZ\Publish\API\Repository\Values\User\Limitation\NewObjectStateLimitation
Definition: NewObjectStateLimitation.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\NewObjectStateLimitationType
NewObjectStateLimitationType is a Content Limitation used on 'state' 'assign' function.
Definition: NewObjectStateLimitationType.php:30
eZ\Publish\Core\Limitation\NewObjectStateLimitationType\buildValue
buildValue(array $limitationValues)
Create the Limitation Value.
Definition: NewObjectStateLimitationType.php:92
eZ\Publish\Core\Limitation\NewObjectStateLimitationType\getCriterion
getCriterion(APILimitationValue $value, APIUserReference $currentUser)
Returns Criterion for use in find() query.
Definition: NewObjectStateLimitationType.php:153
eZ\Publish\Core\Limitation\NewObjectStateLimitationType\evaluate
evaluate(APILimitationValue $value, APIUserReference $currentUser, ValueObject $object, array $targets=null)
Evaluate permission against content & target(placement/parent/assignment).
Definition: NewObjectStateLimitationType.php:112
eZ\Publish\Core\Limitation\NewObjectStateLimitationType\acceptValue
acceptValue(APILimitationValue $limitationValue)
Accepts a Limitation value and checks for structural validity.
Definition: NewObjectStateLimitationType.php:40
eZ\Publish\Core\Limitation\NewObjectStateLimitationType\valueSchema
valueSchema()
Returns info on valid $limitationValues.
Definition: NewObjectStateLimitationType.php:164
eZ\Publish\Core\Limitation\NewObjectStateLimitationType\validate
validate(APILimitationValue $limitationValue)
Makes sure LimitationValue->limitationValues is valid according to valueSchema().
Definition: NewObjectStateLimitationType.php:64
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\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
eZ\Publish\SPI\Persistence\Content\ObjectState
Definition: ObjectState/Group.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.