Skip to content

[DoctrineBridge][DBAL] Add PdoHandler-like $options #20288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,38 @@ class DbalSessionHandler implements \SessionHandlerInterface
/**
* @var string Column for session id
*/
private $idCol = 'sess_id';
private $idCol;

/**
* @var string Column for session data
*/
private $dataCol = 'sess_data';
private $dataCol;

/**
* @var string Column for timestamp
*/
private $timeCol = 'sess_time';
private $timeCol;

/**
* Constructor.
*
* List of available options:
* * db_id_col: The column where to store the session id [default: sess_id]
* * db_data_col: The column where to store the session data [default: sess_data]
* * db_time_col: The column where to store the timestamp [default: sess_time]
*
* @param Connection $con A connection
* @param string $tableName Table name
* @param array $options An associative array of options
*/
public function __construct(Connection $con, $tableName = 'sessions')
public function __construct(Connection $con, $tableName = 'sessions', array $options = array())
{
$this->con = $con;
$this->table = $tableName;

$this->idCol = isset($options['db_id_col']) ? $options['db_id_col'] : 'sess_id';
$this->dataCol = isset($options['db_data_col']) ? $options['db_data_col'] : 'sess_data';
$this->timeCol = isset($options['db_time_col']) ? $options['db_time_col'] : 'sess_time';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@ public function testConstruct()
$connection = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock();
$handler = new DbalSessionHandler($connection);
}

public function testConstructWithTableNameAndOptions()
{
$connection = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock();
$options = array('db_id_col' => 'id', 'db_data_col' => 'data', 'db_time_col' => 'time');
$table = 'sessions';

$handler = new DbalSessionHandler($connection, $table, $options);
}
}