1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the LanguageHandler class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\Core\Persistence\Cache; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\SPI\Persistence\Content\Language\Handler as ContentLanguageHandlerInterface; |
12
|
|
|
use eZ\Publish\SPI\Persistence\Content\Language; |
13
|
|
|
use eZ\Publish\SPI\Persistence\Content\Language\CreateStruct; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @see \eZ\Publish\SPI\Persistence\Content\Language\Handler |
17
|
|
|
*/ |
18
|
|
|
class ContentLanguageHandler extends AbstractInMemoryHandler implements ContentLanguageHandlerInterface |
19
|
|
|
{ |
20
|
|
|
/** @var callable */ |
21
|
|
|
private $getTags; |
22
|
|
|
|
23
|
|
|
/** @var callable */ |
24
|
|
|
private $getKeys; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Set callback functions for use in cache retrieval. |
28
|
|
|
* |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function __construct(...$params) |
32
|
|
|
{ |
33
|
|
|
parent::__construct(...$params); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$this->getTags = static function (Language $language) { return ['language-' . $language->id]; }; |
36
|
|
|
$this->getKeys = static function (Language $language) { |
37
|
|
|
return [ |
38
|
|
|
'ez-language-' . $language->id, |
39
|
|
|
'ez-language-code-' . $language->languageCode, |
40
|
|
|
]; |
41
|
|
|
}; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
View Code Duplication |
public function create(CreateStruct $struct) |
48
|
|
|
{ |
49
|
|
|
$this->logger->logCall(__METHOD__, array('struct' => $struct)); |
50
|
|
|
$this->cache->deleteItems(['ez-language-list']); |
51
|
|
|
|
52
|
|
|
return $this->persistenceHandler->contentLanguageHandler()->create($struct); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
public function update(Language $struct) |
59
|
|
|
{ |
60
|
|
|
$this->logger->logCall(__METHOD__, array('struct' => $struct)); |
61
|
|
|
$return = $this->persistenceHandler->contentLanguageHandler()->update($struct); |
62
|
|
|
|
63
|
|
|
$this->cache->deleteItems([ |
64
|
|
|
'ez-language-list', |
65
|
|
|
'ez-language-' . $struct->id, |
66
|
|
|
'ez-language-code-' . $struct->languageCode, |
67
|
|
|
]); |
68
|
|
|
|
69
|
|
|
return $return; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
|
View Code Duplication |
public function load($id) |
76
|
|
|
{ |
77
|
|
|
return $this->getCacheValue( |
78
|
|
|
$id, |
79
|
|
|
'ez-language-', |
80
|
|
|
function ($id) { |
81
|
|
|
return $this->persistenceHandler->contentLanguageHandler()->load($id); |
82
|
|
|
}, |
83
|
|
|
$this->getTags, |
84
|
|
|
$this->getKeys |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
|
View Code Duplication |
public function loadList(array $ids): iterable |
92
|
|
|
{ |
93
|
|
|
return $this->getMultipleCacheValues( |
|
|
|
|
94
|
|
|
$ids, |
95
|
|
|
'ez-language-', |
96
|
|
|
function (array $ids) { |
97
|
|
|
return $this->persistenceHandler->contentLanguageHandler()->loadList($ids); |
98
|
|
|
}, |
99
|
|
|
$this->getTags, |
100
|
|
|
$this->getKeys |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* {@inheritdoc} |
106
|
|
|
*/ |
107
|
|
View Code Duplication |
public function loadByLanguageCode($languageCode) |
108
|
|
|
{ |
109
|
|
|
return $this->getCacheValue( |
110
|
|
|
$languageCode, |
111
|
|
|
'ez-language-code-', |
112
|
|
|
function ($languageCode) { |
113
|
|
|
return $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode($languageCode); |
114
|
|
|
}, |
115
|
|
|
$this->getTags, |
116
|
|
|
$this->getKeys |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* {@inheritdoc} |
122
|
|
|
*/ |
123
|
|
View Code Duplication |
public function loadListByLanguageCodes(array $languageCodes): iterable |
124
|
|
|
{ |
125
|
|
|
return $this->getMultipleCacheValues( |
|
|
|
|
126
|
|
|
$languageCodes, |
127
|
|
|
'ez-language-code-', |
128
|
|
|
function (array $languageCodes) { |
129
|
|
|
return $this->persistenceHandler->contentLanguageHandler()->loadListByLanguageCodes($languageCodes); |
130
|
|
|
}, |
131
|
|
|
$this->getTags, |
132
|
|
|
$this->getKeys |
133
|
|
|
); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* {@inheritdoc} |
138
|
|
|
*/ |
139
|
|
|
public function loadAll() |
140
|
|
|
{ |
141
|
|
|
return $this->getListCacheValue( |
142
|
|
|
'ez-language-list', |
143
|
|
|
function () { |
144
|
|
|
return $this->persistenceHandler->contentLanguageHandler()->loadAll(); |
145
|
|
|
}, |
146
|
|
|
$this->getTags, |
147
|
|
|
$this->getKeys |
148
|
|
|
); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* {@inheritdoc} |
153
|
|
|
*/ |
154
|
|
View Code Duplication |
public function delete($id) |
155
|
|
|
{ |
156
|
|
|
$this->logger->logCall(__METHOD__, array('language' => $id)); |
157
|
|
|
$return = $this->persistenceHandler->contentLanguageHandler()->delete($id); |
158
|
|
|
|
159
|
|
|
// As we don't have locale we clear cache by tag invalidation |
160
|
|
|
$this->cache->invalidateTags(['language-' . $id]); |
161
|
|
|
|
162
|
|
|
return $return; |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|