1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
7
|
|
|
* @package MAdmin |
8
|
|
|
* @subpackage Cache |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\MAdmin\Cache\Item; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Default cache item implementation. |
17
|
|
|
* |
18
|
|
|
* @package MAdmin |
19
|
|
|
* @subpackage Cache |
20
|
|
|
*/ |
21
|
|
|
class Standard |
22
|
|
|
extends \Aimeos\MShop\Common\Item\Base |
|
|
|
|
23
|
|
|
implements \Aimeos\MAdmin\Cache\Item\Iface |
24
|
|
|
{ |
25
|
|
|
private $values; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Initializes the log item. |
30
|
|
|
* |
31
|
|
|
* @param array $values Associative list of key/value pairs |
32
|
|
|
*/ |
33
|
|
|
public function __construct( array $values = [] ) |
34
|
|
|
{ |
35
|
|
|
parent::__construct( 'cache.', $values ); |
36
|
|
|
|
37
|
|
|
$this->values = $values; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Returns the ID of the item if available. |
43
|
|
|
* |
44
|
|
|
* @return string|null ID of the item |
45
|
|
|
*/ |
46
|
|
|
public function getId() |
47
|
|
|
{ |
48
|
|
|
if( isset( $this->values['id'] ) ) { |
49
|
|
|
return (string) $this->values['id']; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Sets the unique ID of the item. |
56
|
|
|
* |
57
|
|
|
* @param string $id Unique ID of the item |
58
|
|
|
* @return \Aimeos\MAdmin\Cache\Item\Iface Cache item for chaining method calls |
59
|
|
|
*/ |
60
|
|
|
public function setId( $id ) |
61
|
|
|
{ |
62
|
|
|
if( (string) $id !== $this->getId() ) |
63
|
|
|
{ |
64
|
|
|
$this->values['id'] = (string) $id; |
65
|
|
|
$this->setModified(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Returns the ID of the site the item is stored |
74
|
|
|
* |
75
|
|
|
* @return string|null Site ID (or null if not available) |
76
|
|
|
*/ |
77
|
|
|
public function getSiteId() |
78
|
|
|
{ |
79
|
|
|
if( isset( $this->values['siteid'] ) ) { |
80
|
|
|
return (string) $this->values['siteid']; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Returns the value associated to the key. |
87
|
|
|
* |
88
|
|
|
* @return string Returns the value of the item |
89
|
|
|
*/ |
90
|
|
|
public function getValue() |
91
|
|
|
{ |
92
|
|
|
if( isset( $this->values['value'] ) ) { |
93
|
|
|
return (string) $this->values['value']; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return ''; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Sets the new value of the item. |
102
|
|
|
* |
103
|
|
|
* @param string $value Value of the item or null for no expiration |
104
|
|
|
* @return \Aimeos\MAdmin\Cache\Item\Iface Cache item for chaining method calls |
105
|
|
|
*/ |
106
|
|
|
public function setValue( $value ) |
107
|
|
|
{ |
108
|
|
|
if( (string) $value !== $this->getValue() ) |
109
|
|
|
{ |
110
|
|
|
$this->values['value'] = (string) $value; |
111
|
|
|
$this->setModified(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Returns the expiration time of the item. |
120
|
|
|
* |
121
|
|
|
* @return string|null Expiration time of the item or null for no expiration |
122
|
|
|
*/ |
123
|
|
|
public function getTimeExpire() |
124
|
|
|
{ |
125
|
|
|
if( isset( $this->values['expire'] ) ) { |
126
|
|
|
return (string) $this->values['expire']; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Sets the new expiration time of the item. |
133
|
|
|
* |
134
|
|
|
* @param string|null $timestamp Expiration time of the item |
135
|
|
|
* @return \Aimeos\MAdmin\Cache\Item\Iface Cache item for chaining method calls |
136
|
|
|
*/ |
137
|
|
|
public function setTimeExpire( $timestamp ) |
138
|
|
|
{ |
139
|
|
|
if( $timestamp !== $this->getValue() ) |
140
|
|
|
{ |
141
|
|
|
$this->values['expire'] = $this->checkDateFormat( $timestamp ); |
142
|
|
|
$this->setModified(); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return $this; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Returns the tags associated to the item. |
151
|
|
|
* |
152
|
|
|
* @return array Tags associated to the item |
153
|
|
|
*/ |
154
|
|
|
public function getTags() |
155
|
|
|
{ |
156
|
|
|
if( isset( $this->values['tags'] ) ) { |
157
|
|
|
return (array) $this->values['tags']; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
return []; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Sets the new tags associated to the item. |
166
|
|
|
* |
167
|
|
|
* @param array Tags associated to the item |
168
|
|
|
* @return \Aimeos\MAdmin\Cache\Item\Iface Cache item for chaining method calls |
169
|
|
|
*/ |
170
|
|
|
public function setTags( array $tags ) |
171
|
|
|
{ |
172
|
|
|
$this->values['tags'] = $tags; |
173
|
|
|
$this->setModified(); |
174
|
|
|
|
175
|
|
|
return $this; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Returns the item type |
181
|
|
|
* |
182
|
|
|
* @return string Item type, subtypes are separated by slashes |
183
|
|
|
*/ |
184
|
|
|
public function getResourceType() |
185
|
|
|
{ |
186
|
|
|
return 'cache'; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Sets the item values from the given array. |
192
|
|
|
* |
193
|
|
|
* @param array $list Associative list of item keys and their values |
194
|
|
|
* @return array Associative list of keys and their values that are unknown |
195
|
|
|
*/ |
196
|
|
|
public function fromArray( array $list ) |
197
|
|
|
{ |
198
|
|
|
$unknown = []; |
199
|
|
|
$list = parent::fromArray( $list ); |
200
|
|
|
|
201
|
|
|
foreach( $list as $key => $value ) |
202
|
|
|
{ |
203
|
|
|
switch( $key ) |
204
|
|
|
{ |
205
|
|
|
case 'cache.id': $this->setId( $value ); break; |
206
|
|
|
case 'cache.value': $this->setValue( $value ); break; |
207
|
|
|
case 'cache.expire': $this->setTimeExpire( $value ); break; |
208
|
|
|
case 'cache.tags': $this->setTags( $value ); break; |
209
|
|
|
default: $unknown[$key] = $value; |
|
|
|
|
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
return $unknown; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Returns the item values as array. |
219
|
|
|
* |
220
|
|
|
* @param boolean True to return private properties, false for public only |
221
|
|
|
* @return array Associative list of item properties and their values |
222
|
|
|
*/ |
223
|
|
|
public function toArray( $private = false ) |
224
|
|
|
{ |
225
|
|
|
$list = []; |
226
|
|
|
|
227
|
|
|
$list['cache.id'] = $this->getId(); |
228
|
|
|
$list['cache.value'] = $this->getValue(); |
229
|
|
|
$list['cache.expire'] = $this->getTimeExpire(); |
230
|
|
|
$list['cache.tags'] = $this->getTags(); |
231
|
|
|
|
232
|
|
|
if( $private === true ) { |
233
|
|
|
$list['cache.siteid'] = $this->getSiteId(); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
return $list; |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
|