3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Cache\Storage\Adapter
;
12 use APCIterator
as BaseApcIterator
;
13 use Zend\Cache\Storage\IteratorInterface
;
15 class ApcIterator
implements IteratorInterface
18 * The apc storage instance
29 protected $mode = IteratorInterface
::CURRENT_AS_KEY
;
32 * The base APCIterator instance
34 * @var BaseApcIterator
36 protected $baseIterator;
39 * The length of the namespace prefix
43 protected $prefixLength;
49 * @param BaseApcIterator $baseIterator
50 * @param string $prefix
52 public function __construct(Apc
$storage, BaseApcIterator
$baseIterator, $prefix)
54 $this->storage
= $storage;
55 $this->baseIterator
= $baseIterator;
56 $this->prefixLength
= strlen($prefix);
60 * Get storage instance
64 public function getStorage()
66 return $this->storage
;
72 * @return int Value of IteratorInterface::CURRENT_AS_*
74 public function getMode()
83 * @return ApcIterator Provides a fluent interface
85 public function setMode($mode)
87 $this->mode
= (int) $mode;
94 * Get current key, value or metadata.
98 public function current()
100 if ($this->mode
== IteratorInterface
::CURRENT_AS_SELF
) {
106 if ($this->mode
== IteratorInterface
::CURRENT_AS_VALUE
) {
107 return $this->storage
->getItem($key);
108 } elseif ($this->mode
== IteratorInterface
::CURRENT_AS_METADATA
) {
109 return $this->storage
->getMetadata($key);
120 public function key()
122 $key = $this->baseIterator
->key();
124 // remove namespace prefix
125 return substr($key, $this->prefixLength
);
129 * Move forward to next element
133 public function next()
135 $this->baseIterator
->next();
139 * Checks if current position is valid
143 public function valid()
145 return $this->baseIterator
->valid();
149 * Rewind the Iterator to the first element.
153 public function rewind()
155 return $this->baseIterator
->rewind();