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
;
13 use Zend\Cache\Storage\IteratorInterface
;
14 use Zend\Cache\Storage\StorageInterface
;
16 class KeyListIterator
implements IteratorInterface
, Countable
20 * The storage instance
22 * @var StorageInterface
31 protected $mode = IteratorInterface
::CURRENT_AS_KEY
;
34 * Keys to iterate over
48 * Current iterator position
52 protected $position = 0;
57 * @param StorageInterface $storage
60 public function __construct(StorageInterface
$storage, array $keys)
62 $this->storage
= $storage;
64 $this->count
= count($keys);
68 * Get storage instance
70 * @return StorageInterface
72 public function getStorage()
74 return $this->storage
;
80 * @return int Value of IteratorInterface::CURRENT_AS_*
82 public function getMode()
91 * @return KeyListIterator Fluent interface
93 public function setMode($mode)
95 $this->mode
= (int) $mode;
100 * Get current key, value or metadata.
104 public function current()
106 if ($this->mode
== IteratorInterface
::CURRENT_AS_SELF
) {
112 if ($this->mode
== IteratorInterface
::CURRENT_AS_METADATA
) {
113 return $this->storage
->getMetadata($key);
114 } elseif ($this->mode
== IteratorInterface
::CURRENT_AS_VALUE
) {
115 return $this->storage
->getItem($key);
126 public function key()
128 return $this->keys
[$this->position
];
132 * Checks if current position is valid
136 public function valid()
138 return $this->position
< $this->count
;
142 * Move forward to next element
146 public function next()
152 * Rewind the Iterator to the first element.
156 public function rewind()
162 * Count number of items
166 public function count()