類別 yii\web\SessionIterator
繼承關係 | yii\web\SessionIterator |
---|---|
實作 | Iterator |
自版本起可用 | 2.0 |
原始碼 | https://github.com/yiisoft/yii2/blob/master/framework/web/SessionIterator.php |
SessionIterator 實作了一個 iterator,用於遍歷由 yii\web\Session 管理的 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]));
}
倒回內部陣列指標。
此方法為 Iterator 介面所要求。
public void rewind ( ) |
#[\ReturnTypeWillChange]
public function rewind()
{
$this->_key = reset($this->_keys);
}
註冊 或 登入 以便評論。