composer package updates
[openemr.git] / vendor / zendframework / zend-cache / src / Storage / Adapter / ApcuIterator.php
blob0eb2881fffd423ac4c1445897a7f2fb585433ebd
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-2016 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 Zend\Cache\Storage\IteratorInterface;
13 use APCuIterator as BaseApcuIterator;
15 class ApcuIterator implements IteratorInterface
17 /**
18 * The storage instance
20 * @var Apcu
22 protected $storage;
24 /**
25 * The iterator mode
27 * @var int
29 protected $mode = IteratorInterface::CURRENT_AS_KEY;
31 /**
32 * The base APCIterator instance
34 * @var APCIterator
36 protected $baseIterator;
38 /**
39 * The length of the namespace prefix
41 * @var int
43 protected $prefixLength;
45 /**
46 * Constructor
48 * @param Apcu $storage
49 * @param BaseApcuIterator $baseIterator
50 * @param string $prefix
52 public function __construct(Apcu $storage, BaseApcuIterator $baseIterator, $prefix)
54 $this->storage = $storage;
55 $this->baseIterator = $baseIterator;
56 $this->prefixLength = strlen($prefix);
59 /**
60 * Get storage instance
62 * @return Apcu
64 public function getStorage()
66 return $this->storage;
69 /**
70 * Get iterator mode
72 * @return int Value of IteratorInterface::CURRENT_AS_*
74 public function getMode()
76 return $this->mode;
79 /**
80 * Set iterator mode
82 * @param int $mode
83 * @return ApcuIterator Provides a fluent interface
85 public function setMode($mode)
87 $this->mode = (int) $mode;
88 return $this;
91 /* Iterator */
93 /**
94 * Get current key, value or metadata.
96 * @return mixed
98 public function current()
100 if ($this->mode == IteratorInterface::CURRENT_AS_SELF) {
101 return $this;
104 $key = $this->key();
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);
112 return $key;
116 * Get current key
118 * @return string
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
131 * @return void
133 public function next()
135 $this->baseIterator->next();
139 * Checks if current position is valid
141 * @return bool
143 public function valid()
145 return $this->baseIterator->valid();
149 * Rewind the Iterator to the first element.
151 * @return void
153 public function rewind()
155 return $this->baseIterator->rewind();