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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* @see https://github.com/laminas/laminas-cache for the canonical source repository
* @copyright https://github.com/laminas/laminas-cache/blob/master/COPYRIGHT.md
* @license https://github.com/laminas/laminas-cache/blob/master/LICENSE.md New BSD License
*/
namespace Laminas\Cache\Storage\Adapter;
use APCIterator as BaseApcIterator;
use Laminas\Cache\Storage\IteratorInterface;
class ApcIterator implements IteratorInterface
{
/**
* The apc storage instance
*
* @var Apc
*/
protected $storage;
/**
* The iterator mode
*
* @var int
*/
protected $mode = IteratorInterface::CURRENT_AS_KEY;
/**
* The base APCIterator instance
*
* @var BaseApcIterator
*/
protected $baseIterator;
/**
* The length of the namespace prefix
*
* @var int
*/
protected $prefixLength;
/**
* Constructor
*
* @param Apc $storage
* @param BaseApcIterator $baseIterator
* @param string $prefix
*/
public function __construct(Apc $storage, BaseApcIterator $baseIterator, $prefix)
{
$this->storage = $storage;
$this->baseIterator = $baseIterator;
$this->prefixLength = strlen($prefix);
}
/**
* Get storage instance
*
* @return Apc
*/
public function getStorage()
{
return $this->storage;
}
/**
* Get iterator mode
*
* @return int Value of IteratorInterface::CURRENT_AS_*
*/
public function getMode()
{
return $this->mode;
}
/**
* Set iterator mode
*
* @param int $mode
* @return ApcIterator Provides a fluent interface
*/
public function setMode($mode)
{
$this->mode = (int) $mode;
return $this;
}
/* Iterator */
/**
* Get current key, value or metadata.
*
* @return mixed
*/
public function current()
{
if ($this->mode == IteratorInterface::CURRENT_AS_SELF) {
return $this;
}
$key = $this->key();
if ($this->mode == IteratorInterface::CURRENT_AS_VALUE) {
return $this->storage->getItem($key);
} elseif ($this->mode == IteratorInterface::CURRENT_AS_METADATA) {
return $this->storage->getMetadata($key);
}
return $key;
}
/**
* Get current key
*
* @return string
*/
public function key()
{
$key = $this->baseIterator->key();
// remove namespace prefix
return substr($key, $this->prefixLength);
}
/**
* Move forward to next element
*
* @return void
*/
public function next()
{
$this->baseIterator->next();
}
/**
* Checks if current position is valid
*
* @return bool
*/
public function valid()
{
return $this->baseIterator->valid();
}
/**
* Rewind the Iterator to the first element.
*
* @return void
*/
public function rewind()
{
return $this->baseIterator->rewind();
}
}