From 460c696aef9fc298fcf15dfa0ac3bddfc488049f Mon Sep 17 00:00:00 2001 From: Diego Saint Esteben Date: Mon, 17 Jun 2013 22:45:30 -0300 Subject: [PATCH] [HttpFoundation] Add accessors methods to session handlers --- src/Symfony/Component/HttpFoundation/CHANGELOG.md | 1 + .../Session/Storage/Handler/MemcacheSessionHandler.php | 10 ++++++++++ .../Storage/Handler/MemcachedSessionHandler.php | 10 ++++++++++ .../Session/Storage/Handler/MongoDbSessionHandler.php | 10 ++++++++++ .../Session/Storage/Handler/PdoSessionHandler.php | 10 ++++++++++ .../Storage/Handler/MemcacheSessionHandlerTest.php | 8 ++++++++ .../Storage/Handler/MemcachedSessionHandlerTest.php | 8 ++++++++ .../Storage/Handler/MongoDbSessionHandlerTest.php | 8 ++++++++ .../Session/Storage/Handler/PdoSessionHandlerTest.php | 10 ++++++++++ 9 files changed, 75 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/CHANGELOG.md b/src/Symfony/Component/HttpFoundation/CHANGELOG.md index 6f02b1d2fb..954b66ac43 100644 --- a/src/Symfony/Component/HttpFoundation/CHANGELOG.md +++ b/src/Symfony/Component/HttpFoundation/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG ----- * added Request::getEncodings() + * added accessors methods to session handlers 2.3.0 ----- diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcacheSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcacheSessionHandler.php index 4a5e63989a..b2384505ae 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcacheSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcacheSessionHandler.php @@ -106,4 +106,14 @@ class MemcacheSessionHandler implements \SessionHandlerInterface // not required here because memcache will auto expire the records anyhow. return true; } + + /** + * Return a Memcache instance + * + * @return \Memcache + */ + protected function getMemcache() + { + return $this->memcache; + } } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php index b3ca0bd3cd..ed7d6edf4b 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php @@ -112,4 +112,14 @@ class MemcachedSessionHandler implements \SessionHandlerInterface // not required here because memcached will auto expire the records anyhow. return true; } + + /** + * Return a Memcached instance + * + * @return \Memcached + */ + protected function getMemcached() + { + return $this->memcached; + } } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php index 69ebae9542..4d819fe3f8 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php @@ -160,4 +160,14 @@ class MongoDbSessionHandler implements \SessionHandlerInterface return $this->collection; } + + /** + * Return a Mongo instance + * + * @return \Mongo + */ + protected function getMongo() + { + return $this->mongo; + } } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php index 347cbee706..baf8eea8f6 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php @@ -240,4 +240,14 @@ class PdoSessionHandler implements \SessionHandlerInterface return true; } + + /** + * Return a PDO instance + * + * @return \PDO + */ + protected function getConnection() + { + return $this->pdo; + } } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php index da0440d428..f313edb681 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MemcacheSessionHandlerTest.php @@ -121,4 +121,12 @@ class MemcacheSessionHandlerTest extends \PHPUnit_Framework_TestCase array(array('expiretime' => 100, 'foo' => 'bar'), false), ); } + + public function testGetConnection() + { + $method = new \ReflectionMethod($this->storage, 'getMemcache'); + $method->setAccessible(true); + + $this->assertInstanceOf('\Memcache', $method->invoke($this->storage)); + } } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php index 7fbfd0a479..4d32094b41 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MemcachedSessionHandlerTest.php @@ -116,4 +116,12 @@ class MemcachedSessionHandlerTest extends \PHPUnit_Framework_TestCase array(array('expiretime' => 100, 'foo' => 'bar'), false), ); } + + public function testGetConnection() + { + $method = new \ReflectionMethod($this->storage, 'getMemcached'); + $method->setAccessible(true); + + $this->assertInstanceOf('\Memcached', $method->invoke($this->storage)); + } } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php index 1cfd1175cb..2c214a5ce5 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php @@ -168,4 +168,12 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->storage->gc(-1)); } + + public function testGetConnection() + { + $method = new \ReflectionMethod($this->storage, 'getMongo'); + $method->setAccessible(true); + + $this->assertInstanceOf('\Mongo', $method->invoke($this->storage)); + } } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php index 1abf3844c6..7e288feaa6 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php @@ -98,4 +98,14 @@ class PdoSessionHandlerTest extends \PHPUnit_Framework_TestCase $storage->gc(-1); $this->assertEquals(0, count($this->pdo->query('SELECT * FROM sessions')->fetchAll())); } + + public function testGetConnection() + { + $storage = new PdoSessionHandler($this->pdo, array('db_table' => 'sessions'), array()); + + $method = new \ReflectionMethod($storage, 'getConnection'); + $method->setAccessible(true); + + $this->assertInstanceOf('\PDO', $method->invoke($storage)); + } }