类 yii\web\SessionIterator
| 继承关系 | yii\web\SessionIterator |
|---|---|
| 实现 | Iterator |
| 可用版本 | 2.0 |
| 源代码 | https://github.com/yiisoft/yii2/blob/master/framework/web/SessionIterator.php |
SessionIterator 实现了一个 迭代器,用于遍历由 yii\web\Session 管理的会话变量。
公共方法
| 方法 | 描述 | 定义于 |
|---|---|---|
| __construct() | 构造函数。 | yii\web\SessionIterator |
| current() | 返回当前数组元素。 | yii\web\SessionIterator |
| key() | 返回当前数组元素的键。 | yii\web\SessionIterator |
| next() | 将内部指针移动到下一个数组元素。 | yii\web\SessionIterator |
| rewind() | 重设内部数组指针。 | yii\web\SessionIterator |
| valid() | 返回当前位置是否存在元素。 | yii\web\SessionIterator |
方法详情
构造函数。
| public void __construct ( ) |
public function __construct()
{
$this->_keys = array_keys(isset($_SESSION) ? $_SESSION : []);
$this->rewind();
}
返回当前数组元素。
此方法是接口 Iterator 所需的。
| public mixed current ( ) | ||
| 返回 | mixed |
当前数组元素 |
|---|---|---|
#[\ReturnTypeWillChange]
public function current()
{
return $this->_key !== false && isset($_SESSION[$this->_key]) ? $_SESSION[$this->_key] : null;
}
返回当前数组元素的键。
此方法是接口 Iterator 所需的。
| public string|integer|null key ( ) | ||
| 返回 | string|integer|null |
当前数组元素的键 |
|---|---|---|
#[\ReturnTypeWillChange]
public function key()
{
return $this->_key === false ? null : $this->_key;
}
将内部指针移动到下一个数组元素。
此方法是接口 Iterator 所需的。
| public void next ( ) |
#[\ReturnTypeWillChange]
public function next()
{
do {
$this->_key = next($this->_keys);
} while ($this->_key !== false && !isset($_SESSION[$this->_key]));
}
注册 或 登录 以发表评论。