Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Cache / Storage / Adapter / KeyListIterator.php
blob862995cf29c77201d87c8b26e5ff91b0b9e323d3
1 <?php
2 /**
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
8 */
10 namespace Zend\Cache\Storage\Adapter;
12 use Countable;
13 use Zend\Cache\Storage\IteratorInterface;
14 use Zend\Cache\Storage\StorageInterface;
16 class KeyListIterator implements IteratorInterface, Countable
19 /**
20 * The storage instance
22 * @var StorageInterface
24 protected $storage;
26 /**
27 * The iterator mode
29 * @var int
31 protected $mode = IteratorInterface::CURRENT_AS_KEY;
33 /**
34 * Keys to iterate over
36 * @var string[]
38 protected $keys;
40 /**
41 * Number of keys
43 * @var int
45 protected $count;
47 /**
48 * Current iterator position
50 * @var int
52 protected $position = 0;
54 /**
55 * Constructor
57 * @param StorageInterface $storage
58 * @param array $keys
60 public function __construct(StorageInterface $storage, array $keys)
62 $this->storage = $storage;
63 $this->keys = $keys;
64 $this->count = count($keys);
67 /**
68 * Get storage instance
70 * @return StorageInterface
72 public function getStorage()
74 return $this->storage;
77 /**
78 * Get iterator mode
80 * @return int Value of IteratorInterface::CURRENT_AS_*
82 public function getMode()
84 return $this->mode;
87 /**
88 * Set iterator mode
90 * @param int $mode
91 * @return KeyListIterator Fluent interface
93 public function setMode($mode)
95 $this->mode = (int) $mode;
96 return $this;
99 /**
100 * Get current key, value or metadata.
102 * @return mixed
104 public function current()
106 if ($this->mode == IteratorInterface::CURRENT_AS_SELF) {
107 return $this;
110 $key = $this->key();
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);
118 return $key;
122 * Get current key
124 * @return string
126 public function key()
128 return $this->keys[$this->position];
132 * Checks if current position is valid
134 * @return bool
136 public function valid()
138 return $this->position < $this->count;
142 * Move forward to next element
144 * @return void
146 public function next()
148 $this->position++;
152 * Rewind the Iterator to the first element.
154 * @return void
156 public function rewind()
158 $this->position = 0;
162 * Count number of items
164 * @return int
166 public function count()
168 return $this->count;