PHP 클래스 yii\web\MultiFieldSession

With multi-field data storage, session data can be split between several fields in the storage record. Using such a storage allows saving particular session data into separated field, which then can be used to manipulate sessions in the way plain PHP does not allow. For example the ID of the authenticated user can be saved as separated column in the MySQL 'session' table, which allows to query all active sessions for a particular user or terminate them at will. Customizing of the session writing is performed via [[writeCallback]], reading via [[readCallback]]. While extending this class you should use MultiFieldSession::composeFields method - while writing the session data into the storage and MultiFieldSession::extractData - while reading session data from the storage.
부터: 2.0.6
저자: Paul Klimov ([email protected])
상속: extends yii\web\Session
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$readCallback a callback that will be called during session data reading. The signature of the callback should be as follows: function ($fields) where $fields is the storage field set for read session and $session is this session instance. If callback returns an array, it will be merged into the session data. For example: php function ($fields) { return [ 'expireDate' => Yii::$app->formatter->asDate($fields['expire']), ]; }
$writeCallback a callback that will be called during session data writing. The signature of the callback should be as follows: function ($session) where $session is this session instance, this variable can be used to retrieve session data. Callback should return the actual fields set, which should be saved into the session storage. For example: php function ($session) { return [ 'user_id' => Yii::$app->user->id, 'ip' => $_SERVER['REMOTE_ADDR'], 'is_trusted' => $session->get('is_trusted', false), ]; }

공개 메소드들

메소드 설명
getUseCustomStorage ( ) : boolean Returns a value indicating whether to use custom session storage.

보호된 메소드들

메소드 설명
composeFields ( string $id, string $data ) : array Composes storage field set for session writing.
extractData ( array $fields ) : string Extracts session data from storage field set.

메소드 상세

composeFields() 보호된 메소드

Composes storage field set for session writing.
protected composeFields ( string $id, string $data ) : array
$id string session id
$data string session data
리턴 array storage fields

extractData() 보호된 메소드

Extracts session data from storage field set.
protected extractData ( array $fields ) : string
$fields array storage fields.
리턴 string session data.

getUseCustomStorage() 공개 메소드

This method overrides the parent implementation and always returns true.
public getUseCustomStorage ( ) : boolean
리턴 boolean whether to use custom storage.

프로퍼티 상세

$readCallback 공개적으로 프로퍼티

a callback that will be called during session data reading. The signature of the callback should be as follows: function ($fields) where $fields is the storage field set for read session and $session is this session instance. If callback returns an array, it will be merged into the session data. For example: php function ($fields) { return [ 'expireDate' => Yii::$app->formatter->asDate($fields['expire']), ]; }
public $readCallback

$writeCallback 공개적으로 프로퍼티

a callback that will be called during session data writing. The signature of the callback should be as follows: function ($session) where $session is this session instance, this variable can be used to retrieve session data. Callback should return the actual fields set, which should be saved into the session storage. For example: php function ($session) { return [ 'user_id' => Yii::$app->user->id, 'ip' => $_SERVER['REMOTE_ADDR'], 'is_trusted' => $session->get('is_trusted', false), ]; }
public $writeCallback