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

Cache/ObjectStateHandler.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Persistence\Cache;
8
9 use eZ\Publish\SPI\Persistence\Content\ObjectState;
10 use eZ\Publish\SPI\Persistence\Content\ObjectState\Group;
11 use eZ\Publish\SPI\Persistence\Content\ObjectState\Handler as ObjectStateHandlerInterface;
12 use eZ\Publish\SPI\Persistence\Content\ObjectState\InputStruct;
13
17 class ObjectStateHandler extends AbstractInMemoryPersistenceHandler implements ObjectStateHandlerInterface
18 {
19 private const STATE_GROUP_ALL_IDENTIFIER = 'state_group_all';
20 private const STATE_GROUP_IDENTIFIER = 'state_group';
21 private const STATE_GROUP_WITH_ID_SUFFIX_IDENTIFIER = 'state_group_with_id_suffix';
22 private const BY_IDENTIFIER_SUFFIX = 'by_identifier_suffix';
23 private const STATE_IDENTIFIER = 'state';
24 private const STATE_LIST_BY_GROUP_IDENTIFIER = 'state_list_by_group';
25 private const STATE_ID_IDENTIFIER = 'state_identifier';
26 private const STATE_ID_IDENTIFIER_WITH_BY_GROUP_SUFFIX_IDENTIFIER = 'state_identifier_with_by_group_suffix';
27 private const BY_GROUP_IDENTIFIER = 'by_group';
28 private const STATE_BY_GROUP_ON_CONTENT_IDENTIFIER = 'state_by_group_on_content';
29 private const STATE_BY_GROUP_IDENTIFIER = 'state_by_group';
30 private const CONTENT_IDENTIFIER = 'content';
31 private const ON_CONTENT_IDENTIFIER = 'on_content';
32
36 public function createGroup(InputStruct $input)
37 {
38 $this->logger->logCall(__METHOD__, ['struct' => $input]);
39 $group = $this->persistenceHandler->objectStateHandler()->createGroup($input);
40
41 $this->cache->deleteItem(
42 $this->cacheIdentifierGenerator->generateKey(self::STATE_GROUP_ALL_IDENTIFIER, [], true)
43 );
44
45 return $group;
46 }
47
51 public function loadGroup($groupId)
52 {
53 return $this->getCacheValue(
54 (int) $groupId,
55 $this->cacheIdentifierGenerator->generateKey(self::STATE_GROUP_IDENTIFIER, [], true) . '-',
56 function (int $groupId): Group {
57 $this->logger->logCall(__METHOD__, ['groupId' => (int) $groupId]);
58
59 return $this->persistenceHandler->objectStateHandler()->loadGroup($groupId);
60 },
61 function () use ($groupId): array {
62 return [
63 $this->cacheIdentifierGenerator->generateTag(self::STATE_GROUP_IDENTIFIER, [(int) $groupId]),
64 ];
65 },
66 function () use ($groupId) {
67 return [
68 $this->cacheIdentifierGenerator->generateKey(self::STATE_GROUP_IDENTIFIER, [(int) $groupId], true),
69 ];
70 }
71 );
72 }
73
77 public function loadGroupByIdentifier($identifier)
78 {
79 $escapedIdentifier = $this->cacheIdentifierSanitizer->escapeForCacheKey($identifier);
80
81 return $this->getCacheValue(
82 $identifier,
83 $this->cacheIdentifierGenerator->generateKey(self::STATE_GROUP_IDENTIFIER, [], true) . '-',
84 function (string $identifier): Group {
85 $this->logger->logCall(__METHOD__, ['groupId' => $identifier]);
86
87 return $this->persistenceHandler->objectStateHandler()->loadGroupByIdentifier($identifier);
88 },
89 function (Group $group): array {
90 return [
91 $this->cacheIdentifierGenerator->generateTag(self::STATE_GROUP_IDENTIFIER, [$group->id]),
92 ];
93 },
94 function (Group $group) use ($escapedIdentifier): array {
95 return [
96 $this->cacheIdentifierGenerator->generateKey(self::STATE_GROUP_WITH_ID_SUFFIX_IDENTIFIER, [$escapedIdentifier], true),
97 $this->cacheIdentifierGenerator->generateKey(self::STATE_GROUP_IDENTIFIER, [$group->id], true),
98 ];
99 },
100 $this->cacheIdentifierGenerator->generateKey(self::BY_IDENTIFIER_SUFFIX)
101 );
102 }
103
107 public function loadAllGroups($offset = 0, $limit = -1)
108 {
109 $stateGroups = $this->getListCacheValue(
110 $this->cacheIdentifierGenerator->generateKey(self::STATE_GROUP_ALL_IDENTIFIER, [], true),
111 function () use ($offset, $limit): array {
112 $this->logger->logCall(__METHOD__, ['offset' => (int) $offset, 'limit' => (int) $limit]);
113
114 return $this->persistenceHandler->objectStateHandler()->loadAllGroups(0, -1);
115 },
116 function (Group $group): array {
117 return [
118 $this->cacheIdentifierGenerator->generateTag(self::STATE_GROUP_IDENTIFIER, [$group->id]),
119 ];
120 },
121 function (Group $group): array {
122 return [
123 $this->cacheIdentifierGenerator->generateKey(self::STATE_GROUP_IDENTIFIER, [$group->id], true),
124 $this->cacheIdentifierGenerator->generateKey(self::STATE_GROUP_WITH_ID_SUFFIX_IDENTIFIER, [$group->id], true),
125 ];
126 }
127 );
128
129 return \array_slice($stateGroups, $offset, $limit > -1 ? $limit : null);
130 }
131
135 public function loadObjectStates($groupId)
136 {
137 return $this->getCacheValue(
138 $groupId,
139 $this->cacheIdentifierGenerator->generateKey(self::STATE_LIST_BY_GROUP_IDENTIFIER, [], true) . '-',
140 function (int $groupId): array {
141 $this->logger->logCall(__METHOD__, ['groupId' => (int) $groupId]);
142
143 return $this->persistenceHandler->objectStateHandler()->loadObjectStates($groupId);
144 },
145 function (array $objectStates) use ($groupId): array {
146 $cacheTags = [];
147 $cacheTags[] = $this->cacheIdentifierGenerator->generateTag(self::STATE_GROUP_IDENTIFIER, [$groupId]);
148 foreach ($objectStates as $state) {
149 $cacheTags[] = $this->cacheIdentifierGenerator->generateTag(self::STATE_IDENTIFIER, [$state->id]);
150 }
151
152 return $cacheTags;
153 },
154 function () use ($groupId): array {
155 return [
156 $this->cacheIdentifierGenerator->generateKey(self::STATE_LIST_BY_GROUP_IDENTIFIER, [$groupId], true),
157 ];
158 }
159 );
160 }
161
165 public function updateGroup($groupId, InputStruct $input)
166 {
167 $this->logger->logCall(__METHOD__, ['groupId' => $groupId, 'struct' => $input]);
168 $return = $this->persistenceHandler->objectStateHandler()->updateGroup($groupId, $input);
169
170 $this->cache->invalidateTags([
171 $this->cacheIdentifierGenerator->generateTag(self::STATE_GROUP_IDENTIFIER, [$groupId]),
172 ]);
173
174 return $return;
175 }
176
180 public function deleteGroup($groupId)
181 {
182 $this->logger->logCall(__METHOD__, ['groupId' => $groupId]);
183 $return = $this->persistenceHandler->objectStateHandler()->deleteGroup($groupId);
184
185 $this->cache->invalidateTags([
186 $this->cacheIdentifierGenerator->generateTag(self::STATE_GROUP_IDENTIFIER, [$groupId]),
187 ]);
188
189 return $return;
190 }
191
195 public function create($groupId, InputStruct $input)
196 {
197 $this->logger->logCall(__METHOD__, ['groupId' => $groupId, 'struct' => $input]);
198 $return = $this->persistenceHandler->objectStateHandler()->create($groupId, $input);
199
200 $this->cache->deleteItem(
201 $this->cacheIdentifierGenerator->generateKey(self::STATE_LIST_BY_GROUP_IDENTIFIER, [$groupId], true)
202 );
203
204 return $return;
205 }
206
210 public function load($stateId)
211 {
212 return $this->getCacheValue(
213 (int) $stateId,
214 $this->cacheIdentifierGenerator->generateKey(self::STATE_IDENTIFIER, [], true) . '-',
215 function (int $stateId): ObjectState {
216 $this->logger->logCall(__METHOD__, ['stateId' => $stateId]);
217
218 return $this->persistenceHandler->objectStateHandler()->load($stateId);
219 },
220 function (ObjectState $objectState): array {
221 return [
222 $this->cacheIdentifierGenerator->generateTag(self::STATE_IDENTIFIER, [$objectState->id]),
223 $this->cacheIdentifierGenerator->generateTag(self::STATE_GROUP_IDENTIFIER, [$objectState->groupId]),
224 ];
225 },
226 function () use ($stateId): array {
227 return [
228 $this->cacheIdentifierGenerator->generateKey(self::STATE_IDENTIFIER, [$stateId], true),
229 ];
230 }
231 );
232 }
233
237 public function loadByIdentifier($identifier, $groupId)
238 {
239 $escapedIdentifier = $this->cacheIdentifierSanitizer->escapeForCacheKey($identifier);
240
241 return $this->getCacheValue(
242 $identifier,
243 $this->cacheIdentifierGenerator->generateKey(self::STATE_ID_IDENTIFIER, [], true) . '-',
244 function (string $identifier) use ($groupId): ObjectState {
245 $this->logger->logCall(__METHOD__, ['identifier' => $identifier, 'groupId' => (int) $groupId]);
246
247 return $this->persistenceHandler->objectStateHandler()->loadByIdentifier($identifier, (int) $groupId);
248 },
249 function (ObjectState $objectState): array {
250 return [
251 $this->cacheIdentifierGenerator->generateTag(self::STATE_IDENTIFIER, [$objectState->id]),
252 $this->cacheIdentifierGenerator->generateTag(self::STATE_GROUP_IDENTIFIER, [$objectState->groupId]),
253 ];
254 },
255 function () use ($escapedIdentifier, $groupId): array {
256 return [
257 $this->cacheIdentifierGenerator->generateKey(
258 self::STATE_ID_IDENTIFIER_WITH_BY_GROUP_SUFFIX_IDENTIFIER,
259 [$escapedIdentifier, $groupId],
260 true
261 ),
262 ];
263 },
264 '-' . $this->cacheIdentifierGenerator->generateKey(self::BY_GROUP_IDENTIFIER, [$groupId])
265 );
266 }
267
271 public function update($stateId, InputStruct $input)
272 {
273 $this->logger->logCall(__METHOD__, ['stateId' => $stateId, 'struct' => $input]);
274 $return = $this->persistenceHandler->objectStateHandler()->update($stateId, $input);
275
276 $this->cache->invalidateTags([
277 $this->cacheIdentifierGenerator->generateTag(self::STATE_IDENTIFIER, [$stateId]),
278 ]);
279
280 return $return;
281 }
282
286 public function setPriority($stateId, $priority)
287 {
288 $this->logger->logCall(__METHOD__, ['stateId' => $stateId, 'priority' => $priority]);
289 $return = $this->persistenceHandler->objectStateHandler()->setPriority($stateId, $priority);
290
291 $this->cache->invalidateTags([
292 $this->cacheIdentifierGenerator->generateTag(self::STATE_IDENTIFIER, [$stateId]),
293 ]);
294
295 return $return;
296 }
297
301 public function delete($stateId)
302 {
303 $this->logger->logCall(__METHOD__, ['stateId' => $stateId]);
304 $return = $this->persistenceHandler->objectStateHandler()->delete($stateId);
305
306 $this->cache->invalidateTags([
307 $this->cacheIdentifierGenerator->generateTag(self::STATE_IDENTIFIER, [$stateId]),
308 ]);
309
310 return $return;
311 }
312
316 public function setContentState($contentId, $groupId, $stateId)
317 {
318 $this->logger->logCall(__METHOD__, ['contentId' => $contentId, 'groupId' => $groupId, 'stateId' => $stateId]);
319 $return = $this->persistenceHandler->objectStateHandler()->setContentState($contentId, $groupId, $stateId);
320
321 $this->cache->deleteItem(
322 $this->cacheIdentifierGenerator->generateKey(
323 self::STATE_BY_GROUP_ON_CONTENT_IDENTIFIER,
324 [$groupId, $contentId],
325 true
326 )
327 );
328
329 return $return;
330 }
331
335 public function getContentState($contentId, $stateGroupId)
336 {
337 return $this->getCacheValue(
338 (int) $stateGroupId,
339 $this->cacheIdentifierGenerator->generateKey(self::STATE_BY_GROUP_IDENTIFIER, [], true) . '-',
340 function (int $stateGroupId) use ($contentId): ObjectState {
341 $this->logger->logCall(__METHOD__, ['contentId' => (int) $contentId, 'stateGroupId' => $stateGroupId]);
342
343 return $this->persistenceHandler->objectStateHandler()->getContentState((int) $contentId, $stateGroupId);
344 },
345 function (ObjectState $contentState) use ($contentId): array {
346 return [
347 $this->cacheIdentifierGenerator->generateTag(self::STATE_IDENTIFIER, [$contentState->id]),
348 $this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$contentId]),
349 ];
350 },
351 function () use ($contentId, $stateGroupId): array {
352 return [
353 $this->cacheIdentifierGenerator->generateKey(
354 self::STATE_BY_GROUP_ON_CONTENT_IDENTIFIER,
355 [$stateGroupId, $contentId],
356 true
357 ),
358 ];
359 },
360 '-' . $this->cacheIdentifierGenerator->generateKey(self::ON_CONTENT_IDENTIFIER, [$contentId])
361 );
362 }
363
367 public function getContentCount($stateId)
368 {
369 $this->logger->logCall(__METHOD__, ['stateId' => $stateId]);
370
371 return $this->persistenceHandler->objectStateHandler()->getContentCount($stateId);
372 }
373 }
eZ\Publish\Core\Persistence\Cache\AbstractInMemoryHandler\getListCacheValue
getListCacheValue(string $key, callable $backendLoader, callable $cacheTagger, callable $cacheIndexes, callable $listTags=null, array $arguments=[])
Load list of objects of some type and loggs the hits / misses.
Definition: AbstractInMemoryHandler.php:127
eZ\Publish\Core\Persistence\Cache\AbstractInMemoryHandler\getCacheValue
getCacheValue( $id, string $keyPrefix, callable $backendLoader, callable $cacheTagger, callable $cacheIndexes, string $keySuffix='', array $arguments=[])
Load one cache item from cache and loggs the hits / misses.
Definition: AbstractInMemoryHandler.php:71
eZ\Publish\Core\Persistence\Cache\AbstractInMemoryPersistenceHandler
Internal abstract handler for use in other SPI Persistence Cache Handlers.
Definition: AbstractInMemoryPersistenceHandler.php:22
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler
Definition: Cache/ObjectStateHandler.php:18
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\createGroup
createGroup(InputStruct $input)
{Creates a new object state group.\eZ\Publish\SPI\Persistence\Content\ObjectState\Group}
Definition: Cache/ObjectStateHandler.php:36
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\getContentState
getContentState($contentId, $stateGroupId)
{Gets the object-state of object identified by $contentId.The $state is the id of the state within on...
Definition: Cache/ObjectStateHandler.php:335
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\setContentState
setContentState($contentId, $groupId, $stateId)
{Sets the object-state of a state group to $stateId for the given content.bool}
Definition: Cache/ObjectStateHandler.php:316
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\STATE_GROUP_IDENTIFIER
const STATE_GROUP_IDENTIFIER
Definition: Cache/ObjectStateHandler.php:20
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\getContentCount
getContentCount($stateId)
{Returns the number of objects which are in this state.int}
Definition: Cache/ObjectStateHandler.php:367
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\loadObjectStates
loadObjectStates($groupId)
{This method returns the ordered list of object states of a group.\eZ\Publish\SPI\Persistence\Content...
Definition: Cache/ObjectStateHandler.php:135
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\STATE_BY_GROUP_IDENTIFIER
const STATE_BY_GROUP_IDENTIFIER
Definition: Cache/ObjectStateHandler.php:29
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\CONTENT_IDENTIFIER
const CONTENT_IDENTIFIER
Definition: Cache/ObjectStateHandler.php:30
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\loadAllGroups
loadAllGroups($offset=0, $limit=-1)
{Loads all object state groups.\eZ\Publish\SPI\Persistence\Content\ObjectState\Group[]}
Definition: Cache/ObjectStateHandler.php:107
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\deleteGroup
deleteGroup($groupId)
{Deletes a object state group including all states and links to content.}
Definition: Cache/ObjectStateHandler.php:180
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\STATE_GROUP_ALL_IDENTIFIER
const STATE_GROUP_ALL_IDENTIFIER
Definition: Cache/ObjectStateHandler.php:19
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\loadGroup
loadGroup($groupId)
{Loads a object state group.}
Definition: Cache/ObjectStateHandler.php:51
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\STATE_ID_IDENTIFIER
const STATE_ID_IDENTIFIER
Definition: Cache/ObjectStateHandler.php:25
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\STATE_GROUP_WITH_ID_SUFFIX_IDENTIFIER
const STATE_GROUP_WITH_ID_SUFFIX_IDENTIFIER
Definition: Cache/ObjectStateHandler.php:21
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\create
create($groupId, InputStruct $input)
{Creates a new object state in the given group.The new state gets the last priority....
Definition: Cache/ObjectStateHandler.php:195
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\update
update($stateId, InputStruct $input)
{Updates an object state.\eZ\Publish\SPI\Persistence\Content\ObjectState}
Definition: Cache/ObjectStateHandler.php:271
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\STATE_BY_GROUP_ON_CONTENT_IDENTIFIER
const STATE_BY_GROUP_ON_CONTENT_IDENTIFIER
Definition: Cache/ObjectStateHandler.php:28
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\BY_IDENTIFIER_SUFFIX
const BY_IDENTIFIER_SUFFIX
Definition: Cache/ObjectStateHandler.php:22
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\loadByIdentifier
loadByIdentifier($identifier, $groupId)
{Loads an object state by identifier and group it belongs to.}
Definition: Cache/ObjectStateHandler.php:237
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\setPriority
setPriority($stateId, $priority)
{Changes the priority of the state.}
Definition: Cache/ObjectStateHandler.php:286
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\updateGroup
updateGroup($groupId, InputStruct $input)
{Updates an object state group.\eZ\Publish\SPI\Persistence\Content\ObjectState\Group}
Definition: Cache/ObjectStateHandler.php:165
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\load
load($stateId)
{Loads an object state.}
Definition: Cache/ObjectStateHandler.php:210
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\loadGroupByIdentifier
loadGroupByIdentifier($identifier)
{Loads a object state group by identifier.}
Definition: Cache/ObjectStateHandler.php:77
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\STATE_ID_IDENTIFIER_WITH_BY_GROUP_SUFFIX_IDENTIFIER
const STATE_ID_IDENTIFIER_WITH_BY_GROUP_SUFFIX_IDENTIFIER
Definition: Cache/ObjectStateHandler.php:26
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\STATE_IDENTIFIER
const STATE_IDENTIFIER
Definition: Cache/ObjectStateHandler.php:23
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\BY_GROUP_IDENTIFIER
const BY_GROUP_IDENTIFIER
Definition: Cache/ObjectStateHandler.php:27
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\STATE_LIST_BY_GROUP_IDENTIFIER
const STATE_LIST_BY_GROUP_IDENTIFIER
Definition: Cache/ObjectStateHandler.php:24
eZ\Publish\Core\Persistence\Cache\ObjectStateHandler\ON_CONTENT_IDENTIFIER
const ON_CONTENT_IDENTIFIER
Definition: Cache/ObjectStateHandler.php:31
eZ\Publish\SPI\Persistence\Content\ObjectState\Group
This class represents a persistent object state group.
Definition: ObjectState/Group.php:15
eZ\Publish\SPI\Persistence\Content\ObjectState\InputStruct
This class represents a value for creating and updating object states and groups.
Definition: InputStruct.php:15
eZ\Publish\SPI\Persistence\Content\ObjectState
This class represents a persistent object state.
Definition: SPI/Persistence/Content/ObjectState.php:15
eZ\Publish\SPI\Persistence\Content\ObjectState\Handler
The Object State Handler interface provides managing of object states and groups.
Definition: SPI/Persistence/Content/ObjectState/Handler.php:13
eZ\Publish\Core\Persistence\Cache
Definition: AbstractHandler.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+.