12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace yii\web;
- class SessionIterator implements \Iterator
- {
-
- private $_keys;
-
- private $_key;
-
- public function __construct()
- {
- $this->_keys = array_keys(isset($_SESSION) ? $_SESSION : []);
- $this->rewind();
- }
-
-
- public function rewind()
- {
- $this->_key = reset($this->_keys);
- }
-
-
- public function key()
- {
- return $this->_key === false ? null : $this->_key;
- }
-
-
- public function current()
- {
- return $this->_key !== false && isset($_SESSION[$this->_key]) ? $_SESSION[$this->_key] : null;
- }
-
-
- public function next()
- {
- do {
- $this->_key = next($this->_keys);
- } while ($this->_key !== false && !isset($_SESSION[$this->_key]));
- }
-
-
- public function valid()
- {
- return $this->_key !== false;
- }
- }
|