* Session extends [[\yii\web\Session]] by using MongoDB as session data storage.
*
* By default, Session stores session data in a collection named 'session' inside the default database.
* This collection is better to be pre-created with fields 'id' and 'expire' indexed.
* The collection name can be changed by setting [[sessionCollection]].
*
* The following example shows how you can configure the application to use Session:
* Add the following to your application config under `components`:
*
* ~~~
* 'session' => [
* 'class' => 'yii\mongodb\Session',
* // 'db' => 'mymongodb',
* // 'sessionCollection' => 'my_session',
* ]
* ~~~
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
classSessionextends\yii\web\Session
{
/**
* @var Connection|string the MongoDB connection object or the application component ID of the MongoDB connection.
* After the Session object is created, if you want to change this property, you should only assign it
* with a MongoDB connection object.
*/
public$db='mongodb';
/**
* @var string|array the name of the MongoDB collection that stores the session data.
*/
public$sessionCollection='session';
/**
* Initializes the Session component.
* This method will initialize the [[db]] property to make sure it refers to a valid MongoDB connection.
* @throws InvalidConfigException if [[db]] is invalid.
*/
publicfunctioninit()
{
if(is_string($this->db)){
$this->db=Yii::$app->getComponent($this->db);
}
if(!$this->dbinstanceofConnection){
thrownewInvalidConfigException($this->className()."::db must be either a MongoDB connection instance or the application component ID of a MongoDB connection.");
}
parent::init();
}
/**
* Returns a value indicating whether to use custom session storage.
* This method overrides the parent implementation and always returns true.
* @return boolean whether to use custom storage.
*/
publicfunctiongetUseCustomStorage()
{
returntrue;
}
/**
* Updates the current session ID with a newly generated one.
* Please refer to <http://php.net/session_regenerate_id> for more details.
* @param boolean $deleteOldSession Whether to delete the old associated session file or not.