[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.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage;
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
/**
|
||||
* MemcachedSessionStorage.
|
||||
|
@ -21,7 +21,7 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
|||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class MemcachedSessionStorage extends AbstractSessionStorage implements \SessionHandlerInterface
|
||||
class MemcachedSessionHandler implements \SessionHandlerInterface
|
||||
{
|
||||
/**
|
||||
* 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->memcachedOptions = $memcachedOptions;
|
||||
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage;
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
/**
|
||||
* NativeFileSessionStorage.
|
||||
|
@ -18,42 +18,24 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
|||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class NativeFileSessionStorage extends AbstractSessionStorage
|
||||
class NativeFileSessionHandler extends NativeSessionHandler
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $savePath;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $savePath Path of directory to save session files.
|
||||
* @param array $options Session configuration options.
|
||||
*
|
||||
* @see AbstractSessionStorage::__construct()
|
||||
* @param string $savePath Path of directory to save session files. Default null will leave setting as defined by PHP.
|
||||
*/
|
||||
public function __construct($savePath = null, array $options = array())
|
||||
public function __construct($savePath = null)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
$this->savePath = $savePath;
|
||||
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function registerSaveHandlers()
|
||||
{
|
||||
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.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage;
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
/**
|
||||
* NativeMemcacheSessionStorage.
|
||||
|
@ -20,13 +20,8 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
|||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class NativeMemcacheSessionStorage extends AbstractSessionStorage
|
||||
class NativeMemcacheSessionHandler extends NativeSessionHandler
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $savePath;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -41,17 +36,14 @@ class NativeMemcacheSessionStorage extends AbstractSessionStorage
|
|||
throw new \RuntimeException('PHP does not have "memcache" session module registered');
|
||||
}
|
||||
|
||||
$this->savePath = $savePath;
|
||||
parent::__construct($options);
|
||||
}
|
||||
if (null === $savePath) {
|
||||
$savePath = ini_get('session.save_path');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function registerSaveHandlers()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
parent::setOptions($options);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage;
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
/**
|
||||
* NativeMemcachedSessionStorage.
|
||||
|
@ -20,13 +20,8 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
|||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class NativeMemcachedSessionStorage extends AbstractSessionStorage
|
||||
class NativeMemcachedSessionHandler extends NativeSessionHandler
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $savePath;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -41,17 +36,14 @@ class NativeMemcachedSessionStorage extends AbstractSessionStorage
|
|||
throw new \RuntimeException('PHP does not have "memcached" session module registered');
|
||||
}
|
||||
|
||||
$this->savePath = $savePath;
|
||||
parent::__construct($options);
|
||||
}
|
||||
if (null === $savePath) {
|
||||
$savePath = ini_get('session.save_path');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function registerSaveHandlers()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
parent::setOptions($options);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage;
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
/**
|
||||
* NativeSqliteSessionStorage.
|
||||
|
@ -18,38 +18,30 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
|||
*
|
||||
* @author Drak <drak@zikula.org>
|
||||
*/
|
||||
class NativeSqliteSessionStorage extends AbstractSessionStorage
|
||||
class NativeSqliteSessionHandler extends NativeSessionHandler
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $dbPath;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $dbPath Path to SQLite database file.
|
||||
* @param array $options Session configuration options.
|
||||
* @param string $savePath Path to SQLite database file itself.
|
||||
* @param array $options Session configuration options.
|
||||
*
|
||||
* @see AbstractSessionStorage::__construct()
|
||||
*/
|
||||
public function __construct($dbPath, array $options = array())
|
||||
public function __construct($savePath, array $options = array())
|
||||
{
|
||||
if (!extension_loaded('sqlite')) {
|
||||
throw new \RuntimeException('PHP does not have "sqlite" session module registered');
|
||||
}
|
||||
|
||||
$this->dbPath = $dbPath;
|
||||
parent::__construct($options);
|
||||
}
|
||||
if (null === $savePath) {
|
||||
$savePath = ini_get('session.save_path');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function registerSaveHandlers()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
parent::setOptions($options);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage;
|
||||
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
|
||||
|
||||
/**
|
||||
* NullSessionStorage.
|
||||
|
@ -20,7 +20,7 @@ namespace Symfony\Component\HttpFoundation\Session\Storage;
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
class NullSessionStorage extends AbstractSessionStorage implements \SessionHandlerInterface
|
||||
class NullSessionHandler implements \SessionHandlerInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
Reference in New Issue