|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Xmf\Key; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Xmf\Key\ArrayStorage |
|
16
|
|
|
* |
|
17
|
|
|
* A non-persisting key storage, mainly for testing |
|
18
|
|
|
* |
|
19
|
|
|
* @category Xmf\Key\StorageInterface |
|
20
|
|
|
* @package Xmf |
|
21
|
|
|
* @author Richard Griffith <[email protected]> |
|
22
|
|
|
* @copyright 2016 XOOPS Project (http://xoops.org) |
|
23
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
24
|
|
|
* @version Release: 1.0 |
|
25
|
|
|
* @link http://xoops.org |
|
26
|
|
|
*/ |
|
27
|
|
|
class ArrayStorage extends \ArrayObject implements StorageInterface |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Save key data by name |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $name key name |
|
33
|
|
|
* @param string $data key data, serialized to string if required |
|
34
|
|
|
* |
|
35
|
|
|
* @return boolean true if key saved, otherwise false |
|
36
|
|
|
*/ |
|
37
|
1 |
|
public function save($name, $data) |
|
38
|
|
|
{ |
|
39
|
1 |
|
$this->offsetSet($name, $data); |
|
40
|
1 |
|
return true; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Fetch key data by name |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $name key name |
|
47
|
|
|
* |
|
48
|
|
|
* @return string|false key data (possibly serialized) or false on error |
|
49
|
|
|
*/ |
|
50
|
1 |
|
public function fetch($name) |
|
51
|
|
|
{ |
|
52
|
1 |
|
if ($this->offsetExists($name)) { |
|
53
|
1 |
|
return $this->offsetGet($name); |
|
54
|
|
|
} |
|
55
|
1 |
|
return false; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Fetch key data by name |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $name key name |
|
62
|
|
|
* |
|
63
|
|
|
* @return boolean true if key exists, otherwise false |
|
64
|
|
|
*/ |
|
65
|
1 |
|
public function exists($name) |
|
66
|
|
|
{ |
|
67
|
1 |
|
return $this->offsetExists($name); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Delete a key |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $name key name |
|
74
|
|
|
* |
|
75
|
|
|
* @return boolean true if key deleted, otherwise false |
|
76
|
|
|
*/ |
|
77
|
1 |
|
public function delete($name) |
|
78
|
|
|
{ |
|
79
|
1 |
|
if ($this->offsetExists($name)) { |
|
80
|
1 |
|
$this->offsetUnset($name); |
|
81
|
1 |
|
return true; |
|
82
|
|
|
} |
|
83
|
1 |
|
return false; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|