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 / FilesystemIterator.php
blob800e038adaab23465754af8915f81d9433cde79b
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 GlobIterator;
13 use Zend\Cache\Storage\IteratorInterface;
15 class FilesystemIterator implements IteratorInterface
18 /**
19 * The Filesystem storage instance
21 * @var Filesystem
23 protected $storage;
25 /**
26 * The iterator mode
28 * @var int
30 protected $mode = IteratorInterface::CURRENT_AS_KEY;
32 /**
33 * The GlobIterator instance
35 * @var GlobIterator
37 protected $globIterator;
39 /**
40 * The namespace sprefix
42 * @var string
44 protected $prefix;
46 /**
47 * String length of namespace prefix
49 * @var int
51 protected $prefixLength;
53 /**
54 * Constructor
56 * @param Filesystem $storage
57 * @param string $path
58 * @param string $prefix
60 public function __construct(Filesystem $storage, $path, $prefix)
62 $this->storage = $storage;
63 $this->globIterator = new GlobIterator($path, GlobIterator::KEY_AS_FILENAME);
64 $this->prefix = $prefix;
65 $this->prefixLength = strlen($prefix);
68 /**
69 * Get storage instance
71 * @return Filesystem
73 public function getStorage()
75 return $this->storage;
78 /**
79 * Get iterator mode
81 * @return int Value of IteratorInterface::CURRENT_AS_*
83 public function getMode()
85 return $this->mode;
88 /**
89 * Set iterator mode
91 * @param int $mode
92 * @return FilesystemIterator Fluent interface
94 public function setMode($mode)
96 $this->mode = (int) $mode;
97 return $this;
100 /* Iterator */
103 * Get current key, value or metadata.
105 * @return mixed
107 public function current()
109 if ($this->mode == IteratorInterface::CURRENT_AS_SELF) {
110 return $this;
113 $key = $this->key();
115 if ($this->mode == IteratorInterface::CURRENT_AS_VALUE) {
116 return $this->storage->getItem($key);
117 } elseif ($this->mode == IteratorInterface::CURRENT_AS_METADATA) {
118 return $this->storage->getMetadata($key);
121 return $key;
125 * Get current key
127 * @return string
129 public function key()
131 $filename = $this->globIterator->key();
133 // return without namespace prefix and file suffix
134 return substr($filename, $this->prefixLength, -4);
138 * Move forward to next element
140 * @return void
142 public function next()
144 $this->globIterator->next();
148 * Checks if current position is valid
150 * @return bool
152 public function valid()
154 try {
155 return $this->globIterator->valid();
156 } catch (\LogicException $e) {
157 // @link https://bugs.php.net/bug.php?id=55701
158 // GlobIterator throws LogicException with message
159 // 'The parent constructor was not called: the object is in an invalid state'
160 return false;
165 * Rewind the Iterator to the first element.
167 * @return bool false if the operation failed.
169 public function rewind()
171 try {
172 return $this->globIterator->rewind();
173 } catch (\LogicException $e) {
174 // @link https://bugs.php.net/bug.php?id=55701
175 // GlobIterator throws LogicException with message
176 // 'The parent constructor was not called: the object is in an invalid state'
177 return false;