From 1a8fe9f4caf6cd489a01020d0bc126f86fc34df6 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Mon, 24 Oct 2016 16:05:16 +0200 Subject: [PATCH 1/5] [DoctrineBridge] Add PdoHandler-like $options Small PR to incorporate the options that are available to `PdoSessionHandler` into the `DbalSessionHandler`. I do not like being forced to use pre-defined values, especially when they go against the code standards of my current project. --- .../Doctrine/HttpFoundation/DbalSessionHandler.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionHandler.php b/src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionHandler.php index d819ff0a6c51e..7661598496e5f 100644 --- a/src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionHandler.php +++ b/src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionHandler.php @@ -56,13 +56,23 @@ class DbalSessionHandler implements \SessionHandlerInterface /** * 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 = []) { $this->con = $con; $this->table = $tableName; + + $this->idCol = isset($options['db_id_col']) ? $options['db_id_col'] : $this->idCol; + $this->dataCol = isset($options['db_data_col']) ? $options['db_data_col'] : $this->dataCol; + $this->timeCol = isset($options['db_time_col']) ? $options['db_time_col'] : $this->timeCol; } /** From 9bcca9d0441b5b911abdfaf1d192ecfcf17d3896 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Mon, 24 Oct 2016 16:10:25 +0200 Subject: [PATCH 2/5] [DoctrineBridge] Adhere to coding standard --- .../Bridge/Doctrine/HttpFoundation/DbalSessionHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionHandler.php b/src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionHandler.php index 7661598496e5f..c651d82f55a75 100644 --- a/src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionHandler.php +++ b/src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionHandler.php @@ -65,7 +65,7 @@ class DbalSessionHandler implements \SessionHandlerInterface * @param string $tableName Table name * @param array $options An associative array of options */ - public function __construct(Connection $con, $tableName = 'sessions', array $options = []) + public function __construct(Connection $con, $tableName = 'sessions', array $options = array()) { $this->con = $con; $this->table = $tableName; From 4bac9531a1ec1f35011590270fb3a303144ecc8c Mon Sep 17 00:00:00 2001 From: Mitchell Date: Thu, 10 Nov 2016 09:26:44 +0100 Subject: [PATCH 3/5] Set default values in constructor. --- .../Doctrine/HttpFoundation/DbalSessionHandler.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionHandler.php b/src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionHandler.php index c651d82f55a75..e587e7d682235 100644 --- a/src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionHandler.php +++ b/src/Symfony/Bridge/Doctrine/HttpFoundation/DbalSessionHandler.php @@ -41,17 +41,17 @@ 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. @@ -70,9 +70,9 @@ public function __construct(Connection $con, $tableName = 'sessions', array $opt $this->con = $con; $this->table = $tableName; - $this->idCol = isset($options['db_id_col']) ? $options['db_id_col'] : $this->idCol; - $this->dataCol = isset($options['db_data_col']) ? $options['db_data_col'] : $this->dataCol; - $this->timeCol = isset($options['db_time_col']) ? $options['db_time_col'] : $this->timeCol; + $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'; } /** From a4e57db7ecf79643c6a7a224ba249596980285c9 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Thu, 10 Nov 2016 09:28:23 +0100 Subject: [PATCH 4/5] Added a test --- .../Tests/HttpFoundation/DbalSessionHandlerTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Symfony/Bridge/Doctrine/Tests/HttpFoundation/DbalSessionHandlerTest.php b/src/Symfony/Bridge/Doctrine/Tests/HttpFoundation/DbalSessionHandlerTest.php index 4f82bc37bbb79..e9ade0122d623 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/HttpFoundation/DbalSessionHandlerTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/HttpFoundation/DbalSessionHandlerTest.php @@ -25,4 +25,14 @@ 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 = ['db_id_col' => 'id', 'db_data_col' => 'data', 'db_time_col' => 'time']; + $table = 'sessions'; + + $handler = new DbalSessionHandler($connection, $table, $options); + + } } From 2b5045f25600f7bb926b9ac2999d1dd88e8580e6 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Thu, 10 Nov 2016 13:04:52 +0100 Subject: [PATCH 5/5] Adhere to coding standard --- .../Doctrine/Tests/HttpFoundation/DbalSessionHandlerTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Tests/HttpFoundation/DbalSessionHandlerTest.php b/src/Symfony/Bridge/Doctrine/Tests/HttpFoundation/DbalSessionHandlerTest.php index e9ade0122d623..a48aa75d4e58d 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/HttpFoundation/DbalSessionHandlerTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/HttpFoundation/DbalSessionHandlerTest.php @@ -29,10 +29,9 @@ public function testConstruct() public function testConstructWithTableNameAndOptions() { $connection = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock(); - $options = ['db_id_col' => 'id', 'db_data_col' => 'data', 'db_time_col' => 'time']; + $options = array('db_id_col' => 'id', 'db_data_col' => 'data', 'db_time_col' => 'time'); $table = 'sessions'; $handler = new DbalSessionHandler($connection, $table, $options); - } }