[HttpFoundation] Refactor session handlers.
This commit is contained in:
parent
23267077ff
commit
0a064d8aa1
@ -9,7 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Symfony\Component\HttpFoundation\Session\Storage;
|
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MemcachedSessionStorage.
|
* MemcachedSessionStorage.
|
||||||
@ -21,7 +21,7 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
|||||||
*
|
*
|
||||||
* @author Drak <drak@zikula.org>
|
* @author Drak <drak@zikula.org>
|
||||||
*/
|
*/
|
||||||
class MemcachedSessionStorage extends AbstractSessionStorage implements \SessionHandlerInterface
|
class MemcachedSessionHandler implements \SessionHandlerInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Memcached driver.
|
* Memcached driver.
|
||||||
@ -63,8 +63,6 @@ class MemcachedSessionStorage extends AbstractSessionStorage implements \Session
|
|||||||
$this->memcached->setOption(\Memcached::OPT_PREFIX_KEY, isset($memcachedOptions['prefix']) ? $memcachedOptions['prefix'] : 'sf2s');
|
$this->memcached->setOption(\Memcached::OPT_PREFIX_KEY, isset($memcachedOptions['prefix']) ? $memcachedOptions['prefix'] : 'sf2s');
|
||||||
|
|
||||||
$this->memcachedOptions = $memcachedOptions;
|
$this->memcachedOptions = $memcachedOptions;
|
||||||
|
|
||||||
parent::__construct($options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Symfony\Component\HttpFoundation\Session\Storage;
|
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NativeFileSessionStorage.
|
* NativeFileSessionStorage.
|
||||||
@ -18,42 +18,24 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
|||||||
*
|
*
|
||||||
* @author Drak <drak@zikula.org>
|
* @author Drak <drak@zikula.org>
|
||||||
*/
|
*/
|
||||||
class NativeFileSessionStorage extends AbstractSessionStorage
|
class NativeFileSessionHandler extends NativeSessionHandler
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $savePath;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param string $savePath Path of directory to save session files.
|
* @param string $savePath Path of directory to save session files. Default null will leave setting as defined by PHP.
|
||||||
* @param array $options Session configuration options.
|
|
||||||
*
|
|
||||||
* @see AbstractSessionStorage::__construct()
|
|
||||||
*/
|
*/
|
||||||
public function __construct($savePath = null, array $options = array())
|
public function __construct($savePath = null)
|
||||||
{
|
{
|
||||||
if (null === $savePath) {
|
if (null === $savePath) {
|
||||||
$savePath = sys_get_temp_dir();
|
$savePath = ini_get('session.save_path');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_dir($savePath)) {
|
if ($savePath && !is_dir($savePath)) {
|
||||||
mkdir($savePath, 0777, true);
|
mkdir($savePath, 0777, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->savePath = $savePath;
|
|
||||||
|
|
||||||
parent::__construct($options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function registerSaveHandlers()
|
|
||||||
{
|
|
||||||
ini_set('session.save_handler', 'files');
|
ini_set('session.save_handler', 'files');
|
||||||
ini_set('session.save_path', $this->savePath);
|
ini_set('session.save_path', $savePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,7 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Symfony\Component\HttpFoundation\Session\Storage;
|
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NativeMemcacheSessionStorage.
|
* NativeMemcacheSessionStorage.
|
||||||
@ -20,13 +20,8 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
|||||||
*
|
*
|
||||||
* @author Drak <drak@zikula.org>
|
* @author Drak <drak@zikula.org>
|
||||||
*/
|
*/
|
||||||
class NativeMemcacheSessionStorage extends AbstractSessionStorage
|
class NativeMemcacheSessionHandler extends NativeSessionHandler
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $savePath;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
@ -41,17 +36,14 @@ class NativeMemcacheSessionStorage extends AbstractSessionStorage
|
|||||||
throw new \RuntimeException('PHP does not have "memcache" session module registered');
|
throw new \RuntimeException('PHP does not have "memcache" session module registered');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->savePath = $savePath;
|
if (null === $savePath) {
|
||||||
parent::__construct($options);
|
$savePath = ini_get('session.save_path');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function registerSaveHandlers()
|
|
||||||
{
|
|
||||||
ini_set('session.save_handler', 'memcache');
|
ini_set('session.save_handler', 'memcache');
|
||||||
ini_set('session.save_path', $this->savePath);
|
ini_set('session.save_path', $savePath);
|
||||||
|
|
||||||
|
$this->setOptions($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,7 +65,5 @@ class NativeMemcacheSessionStorage extends AbstractSessionStorage
|
|||||||
ini_set($key, $value);
|
ini_set($key, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::setOptions($options);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Symfony\Component\HttpFoundation\Session\Storage;
|
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NativeMemcachedSessionStorage.
|
* NativeMemcachedSessionStorage.
|
||||||
@ -20,13 +20,8 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
|||||||
*
|
*
|
||||||
* @author Drak <drak@zikula.org>
|
* @author Drak <drak@zikula.org>
|
||||||
*/
|
*/
|
||||||
class NativeMemcachedSessionStorage extends AbstractSessionStorage
|
class NativeMemcachedSessionHandler extends NativeSessionHandler
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $savePath;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
@ -41,17 +36,14 @@ class NativeMemcachedSessionStorage extends AbstractSessionStorage
|
|||||||
throw new \RuntimeException('PHP does not have "memcached" session module registered');
|
throw new \RuntimeException('PHP does not have "memcached" session module registered');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->savePath = $savePath;
|
if (null === $savePath) {
|
||||||
parent::__construct($options);
|
$savePath = ini_get('session.save_path');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function registerSaveHandlers()
|
|
||||||
{
|
|
||||||
ini_set('session.save_handler', 'memcached');
|
ini_set('session.save_handler', 'memcached');
|
||||||
ini_set('session.save_path', $this->savePath);
|
ini_set('session.save_path', $savePath);
|
||||||
|
|
||||||
|
$this->setOptions($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,7 +64,6 @@ class NativeMemcachedSessionStorage extends AbstractSessionStorage
|
|||||||
ini_set($key, $value);
|
ini_set($key, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::setOptions($options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Symfony\Component\HttpFoundation\Session\Storage;
|
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NativeSqliteSessionStorage.
|
* NativeSqliteSessionStorage.
|
||||||
@ -18,38 +18,30 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
|||||||
*
|
*
|
||||||
* @author Drak <drak@zikula.org>
|
* @author Drak <drak@zikula.org>
|
||||||
*/
|
*/
|
||||||
class NativeSqliteSessionStorage extends AbstractSessionStorage
|
class NativeSqliteSessionHandler extends NativeSessionHandler
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $dbPath;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param string $dbPath Path to SQLite database file.
|
* @param string $savePath Path to SQLite database file itself.
|
||||||
* @param array $options Session configuration options.
|
* @param array $options Session configuration options.
|
||||||
*
|
*
|
||||||
* @see AbstractSessionStorage::__construct()
|
* @see AbstractSessionStorage::__construct()
|
||||||
*/
|
*/
|
||||||
public function __construct($dbPath, array $options = array())
|
public function __construct($savePath, array $options = array())
|
||||||
{
|
{
|
||||||
if (!extension_loaded('sqlite')) {
|
if (!extension_loaded('sqlite')) {
|
||||||
throw new \RuntimeException('PHP does not have "sqlite" session module registered');
|
throw new \RuntimeException('PHP does not have "sqlite" session module registered');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->dbPath = $dbPath;
|
if (null === $savePath) {
|
||||||
parent::__construct($options);
|
$savePath = ini_get('session.save_path');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function registerSaveHandlers()
|
|
||||||
{
|
|
||||||
ini_set('session.save_handler', 'sqlite');
|
ini_set('session.save_handler', 'sqlite');
|
||||||
ini_set('session.save_path', $this->dbPath);
|
ini_set('session.save_path', $savePath);
|
||||||
|
|
||||||
|
$this->setOptions($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,7 +58,5 @@ class NativeSqliteSessionStorage extends AbstractSessionStorage
|
|||||||
ini_set($key, $value);
|
ini_set($key, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::setOptions($options);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Symfony\Component\HttpFoundation\Session\Storage;
|
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NullSessionStorage.
|
* NullSessionStorage.
|
||||||
@ -20,7 +20,7 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
|||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
class NullSessionStorage extends AbstractSessionStorage implements \SessionHandlerInterface
|
class NullSessionHandler implements \SessionHandlerInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
Reference in New Issue
Block a user