3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 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
19 * The apc storage instance
30 protected $mode = IteratorInterface
::CURRENT_AS_KEY
;
33 * The base APCIterator instance
35 * @var BaseApcIterator
37 protected $baseIterator;
40 * The length of the namespace prefix
44 protected $prefixLength;
50 * @param BaseApcIterator $baseIterator
51 * @param string $prefix
53 public function __construct(Apc
$storage, BaseApcIterator
$baseIterator, $prefix)
55 $this->storage
= $storage;
56 $this->baseIterator
= $baseIterator;
57 $this->prefixLength
= strlen($prefix);
61 * Get storage instance
65 public function getStorage()
67 return $this->storage
;
73 * @return int Value of IteratorInterface::CURRENT_AS_*
75 public function getMode()
84 * @return ApcIterator Fluent interface
86 public function setMode($mode)
88 $this->mode
= (int) $mode;
95 * Get current key, value or metadata.
99 public function current()
101 if ($this->mode
== IteratorInterface
::CURRENT_AS_SELF
) {
107 if ($this->mode
== IteratorInterface
::CURRENT_AS_VALUE
) {
108 return $this->storage
->getItem($key);
109 } elseif ($this->mode
== IteratorInterface
::CURRENT_AS_METADATA
) {
110 return $this->storage
->getMetadata($key);
121 public function key()
123 $key = $this->baseIterator
->key();
125 // remove namespace prefix
126 return substr($key, $this->prefixLength
);
130 * Move forward to next element
134 public function next()
136 $this->baseIterator
->next();
140 * Checks if current position is valid
144 public function valid()
146 return $this->baseIterator
->valid();
150 * Rewind the Iterator to the first element.
154 public function rewind()
156 return $this->baseIterator
->rewind();