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 __construct(array $config = []) |
|
92 | |||
93 | /** |
||
94 | * Updates the current session ID with a newly generated one . |
||
95 | * Please refer to <http://php.net/session_regenerate_id> for more details. |
||
96 | * @param bool $deleteOldSession Whether to delete the old associated session file or not. |
||
97 | */ |
||
98 | public function regenerateID($deleteOldSession = false) |
||
140 | |||
141 | /** |
||
142 | * Session read handler. |
||
143 | * @internal Do not call this method directly. |
||
144 | * @param string $id session ID |
||
145 | * @return string the session data |
||
146 | */ |
||
147 | 15 | public function readSession($id) |
|
161 | |||
162 | /** |
||
163 | * Session write handler. |
||
164 | * @internal Do not call this method directly. |
||
165 | * @param string $id session ID |
||
166 | * @param string $data session data |
||
167 | * @return bool whether session write is successful |
||
168 | */ |
||
169 | 15 | public function writeSession($id, $data) |
|
184 | |||
185 | /** |
||
186 | * Session destroy handler. |
||
187 | * @internal Do not call this method directly. |
||
188 | * @param string $id session ID |
||
189 | * @return bool whether session is destroyed successfully |
||
190 | */ |
||
191 | 3 | public function destroySession($id) |
|
199 | |||
200 | /** |
||
201 | * Session GC (garbage collection) handler. |
||
202 | * @internal Do not call this method directly. |
||
203 | * @param int $maxLifetime the number of seconds after which data will be seen as 'garbage' and cleaned up. |
||
204 | * @return bool whether session is GCed successfully |
||
205 | */ |
||
206 | 6 | public function gcSession($maxLifetime) |
|
214 | |||
215 | /** |
||
216 | * Method typecasts $fields before passing them to PDO. |
||
217 | * Default implementation casts field `data` to `\PDO::PARAM_LOB`. |
||
218 | * You can override this method in case you need special type casting. |
||
219 | * |
||
220 | * @param array $fields Fields, that will be passed to PDO. Key - name, Value - value |
||
221 | * @return array |
||
222 | * @since 2.0.13 |
||
223 | */ |
||
224 | 15 | protected function typecastFields($fields) |
|
232 | } |
||
233 |