StoreMemory.php
711 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
class LtStoreMemory implements LtStore
{
protected $stack;
public function add($key, $value)
{
if (isset($this->stack[$key]))
{
return false;
}
else
{
$this->stack[$key] = $value;
return true;
}
}
public function del($key)
{
if (isset($this->stack[$key]))
{
unset($this->stack[$key]);
return true;
}
else
{
return false;
}
}
public function get($key)
{
return isset($this->stack[$key]) ? $this->stack[$key] : false;
}
/**
* key不存在返回false
*
* @return bool
*/
public function update($key, $value)
{
if (!isset($this->stack[$key]))
{
return false;
}
else
{
$this->stack[$key] = $value;
return true;
}
}
}