[HttpFoundation] Add accessors methods to session handlers

This commit is contained in:
Diego Saint Esteben 2013-06-17 22:45:30 -03:00 committed by Fabien Potencier
parent d744ffaaeb
commit 460c696aef
9 changed files with 75 additions and 0 deletions

View File

@ -5,6 +5,7 @@ CHANGELOG
-----
* added Request::getEncodings()
* added accessors methods to session handlers
2.3.0
-----

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -160,4 +160,14 @@ class MongoDbSessionHandler implements \SessionHandlerInterface
return $this->collection;
}
/**
* Return a Mongo instance
*
* @return \Mongo
*/
protected function getMongo()
{
return $this->mongo;
}
}

View File

@ -240,4 +240,14 @@ class PdoSessionHandler implements \SessionHandlerInterface
return true;
}
/**
* Return a PDO instance
*
* @return \PDO
*/
protected function getConnection()
{
return $this->pdo;
}
}

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -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));
}
}