1 | <?php |
||
41 | class DbSession extends MultiFieldSession |
||
42 | { |
||
43 | /** |
||
44 | * @var Connection|array|string the DB connection object or the application component ID of the DB connection. |
||
45 | * After the DbSession object is created, if you want to change this property, you should only assign it |
||
46 | * with a DB connection object. |
||
47 | * Starting from version 2.0.2, this can also be a configuration array for creating the object. |
||
48 | */ |
||
49 | public $db = 'db'; |
||
50 | /** |
||
51 | * @var string the name of the DB table that stores the session data. |
||
52 | * The table should be pre-created as follows: |
||
53 | * |
||
54 | * ```sql |
||
55 | * CREATE TABLE session |
||
56 | * ( |
||
57 | * id CHAR(40) NOT NULL PRIMARY KEY, |
||
58 | * expire INTEGER, |
||
59 | * data BLOB |
||
60 | * ) |
||
61 | * ``` |
||
62 | * |
||
63 | * where 'BLOB' refers to the BLOB-type of your preferred DBMS. Below are the BLOB type |
||
64 | * that can be used for some popular DBMS: |
||
65 | * |
||
66 | * - MySQL: LONGBLOB |
||
67 | * - PostgreSQL: BYTEA |
||
68 | * - MSSQL: BLOB |
||
69 | * |
||
70 | * When using DbSession in a production server, we recommend you create a DB index for the 'expire' |
||
71 | * column in the session table to improve the performance. |
||
72 | * |
||
73 | * Note that according to the php.ini setting of `session.hash_function`, you may need to adjust |
||
74 | * the length of the `id` column. For example, if `session.hash_function=sha256`, you should use |
||
75 | * length 64 instead of 40. |
||
76 | */ |
||
77 | public $sessionTable = '{{%session}}'; |
||
78 | |||
79 | |||
80 | /** |
||
81 | * Initializes the DbSession component. |
||
82 | * This method will initialize the [[db]] property to make sure it refers to a valid DB connection. |
||
83 | * @throws InvalidConfigException if [[db]] is invalid. |
||
84 | */ |
||
85 | 15 | public function init() |
|
90 | 15 | ||
91 | 15 | /** |
|
92 | * Updates the current session ID with a newly generated one . |
||
93 | * Please refer to <http://php.net/session_regenerate_id> for more details. |
||
94 | * @param bool $deleteOldSession Whether to delete the old associated session file or not. |
||
95 | */ |
||
96 | public function regenerateID($deleteOldSession = false) |
||
138 | |||
139 | /** |
||
140 | * Session read handler. |
||
141 | * @internal Do not call this method directly. |
||
142 | * @param string $id session ID |
||
143 | * @return string the session data |
||
144 | */ |
||
145 | public function readSession($id) |
||
159 | 15 | ||
160 | /** |
||
161 | * Session write handler. |
||
162 | * @internal Do not call this method directly. |
||
163 | * @param string $id session ID |
||
164 | * @param string $data session data |
||
165 | * @return bool whether session write is successful |
||
166 | */ |
||
167 | public function writeSession($id, $data) |
||
182 | 15 | ||
183 | /** |
||
184 | * Session destroy handler. |
||
185 | * @internal Do not call this method directly. |
||
186 | * @param string $id session ID |
||
187 | * @return bool whether session is destroyed successfully |
||
188 | */ |
||
189 | public function destroySession($id) |
||
197 | 3 | ||
198 | /** |
||
199 | * Session GC (garbage collection) handler. |
||
200 | * @internal Do not call this method directly. |
||
201 | * @param int $maxLifetime the number of seconds after which data will be seen as 'garbage' and cleaned up. |
||
202 | * @return bool whether session is GCed successfully |
||
203 | */ |
||
204 | public function gcSession($maxLifetime) |
||
212 | 6 | ||
213 | /** |
||
214 | * Method typecasts $fields before passing them to PDO. |
||
215 | * Default implementation casts field `data` to `\PDO::PARAM_LOB`. |
||
216 | * You can override this method in case you need special type casting. |
||
217 | * |
||
218 | * @param array $fields Fields, that will be passed to PDO. Key - name, Value - value |
||
219 | * @return array |
||
220 | * @since 2.0.13 |
||
221 | */ |
||
222 | protected function typecastFields($fields) |
||
230 | } |
||
231 |