1 | <?php |
||
30 | abstract class MultiFieldSession extends Session |
||
31 | { |
||
32 | /** |
||
33 | * @var callable a callback that will be called during session data reading. |
||
34 | * The signature of the callback should be as follows: |
||
35 | * |
||
36 | * ``` |
||
37 | * function ($fields) |
||
38 | * ``` |
||
39 | * |
||
40 | * where `$fields` is the storage field set for read session and `$session` is this session instance. |
||
41 | * If callback returns an array, it will be merged into the session data. |
||
42 | * |
||
43 | * For example: |
||
44 | * |
||
45 | * ```php |
||
46 | * function ($fields) { |
||
47 | * return [ |
||
48 | * 'expireDate' => Yii::$app->formatter->asDate($fields['expire']), |
||
49 | * ]; |
||
50 | * } |
||
51 | * ``` |
||
52 | */ |
||
53 | public $readCallback; |
||
54 | /** |
||
55 | * @var callable a callback that will be called during session data writing. |
||
56 | * The signature of the callback should be as follows: |
||
57 | * |
||
58 | * ``` |
||
59 | * function ($session) |
||
60 | * ``` |
||
61 | * |
||
62 | * where `$session` is this session instance, this variable can be used to retrieve session data. |
||
63 | * Callback should return the actual fields set, which should be saved into the session storage. |
||
64 | * |
||
65 | * For example: |
||
66 | * |
||
67 | * ```php |
||
68 | * function ($session) { |
||
69 | * return [ |
||
70 | * 'user_id' => Yii::$app->user->id, |
||
71 | * 'ip' => $_SERVER['REMOTE_ADDR'], |
||
72 | * 'is_trusted' => $session->get('is_trusted', false), |
||
73 | * ]; |
||
74 | * } |
||
75 | * ``` |
||
76 | */ |
||
77 | public $writeCallback; |
||
78 | |||
79 | |||
80 | /** |
||
81 | * Returns a value indicating whether to use custom session storage. |
||
82 | * This method overrides the parent implementation and always returns true. |
||
83 | * @return bool whether to use custom storage. |
||
84 | */ |
||
85 | public function getUseCustomStorage() |
||
89 | |||
90 | /** |
||
91 | * Composes storage field set for session writing. |
||
92 | * @param string $id session id |
||
93 | * @param string $data session data |
||
94 | * @return array storage fields |
||
95 | */ |
||
96 | 15 | protected function composeFields($id, $data) |
|
118 | |||
119 | /** |
||
120 | * Extracts session data from storage field set. |
||
121 | * @param array $fields storage fields. |
||
122 | * @return string session data. |
||
123 | */ |
||
124 | protected function extractData($fields) |
||
142 | } |
||
143 |