Skip to content

Commit

Permalink
[HttpFoundation] Refactor session handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Drak committed Mar 14, 2012
1 parent 2326707 commit 0a064d8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 89 deletions.
Expand Up @@ -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.
Expand All @@ -21,7 +21,7 @@
*
* @author Drak <drak@zikula.org>
*/
class MemcachedSessionStorage extends AbstractSessionStorage implements \SessionHandlerInterface
class MemcachedSessionHandler implements \SessionHandlerInterface
{
/**
* Memcached driver.
Expand Down Expand Up @@ -63,8 +63,6 @@ public function __construct(\Memcached $memcached, array $memcachedOptions = arr
$this->memcached->setOption(\Memcached::OPT_PREFIX_KEY, isset($memcachedOptions['prefix']) ? $memcachedOptions['prefix'] : 'sf2s');

$this->memcachedOptions = $memcachedOptions;

parent::__construct($options);
}

/**
Expand Down
Expand Up @@ -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.
Expand All @@ -18,42 +18,24 @@
*
* @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);
}
}
}
Expand Up @@ -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.
Expand All @@ -20,13 +20,8 @@
*
* @author Drak <drak@zikula.org>
*/
class NativeMemcacheSessionStorage extends AbstractSessionStorage
class NativeMemcacheSessionHandler extends NativeSessionHandler
{
/**
* @var string
*/
private $savePath;

/**
* Constructor.
*
Expand All @@ -41,17 +36,14 @@ public function __construct($savePath = 'tcp://127.0.0.1:11211?persistent=0', ar
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);
}

/**
Expand All @@ -73,7 +65,5 @@ protected function setOptions(array $options)
ini_set($key, $value);
}
}

parent::setOptions($options);
}
}
Expand Up @@ -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.
Expand All @@ -20,13 +20,8 @@
*
* @author Drak <drak@zikula.org>
*/
class NativeMemcachedSessionStorage extends AbstractSessionStorage
class NativeMemcachedSessionHandler extends NativeSessionHandler
{
/**
* @var string
*/
private $savePath;

/**
* Constructor.
*
Expand All @@ -41,17 +36,14 @@ public function __construct($savePath = '127.0.0.1:11211', array $options = arra
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);
}

/**
Expand All @@ -72,7 +64,6 @@ protected function setOptions(array $options)
ini_set($key, $value);
}
}

parent::setOptions($options);
}

}
Expand Up @@ -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.
Expand All @@ -18,38 +18,30 @@
*
* @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);
}

/**
Expand All @@ -66,7 +58,5 @@ protected function setOptions(array $options)
ini_set($key, $value);
}
}

parent::setOptions($options);
}
}
Expand Up @@ -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.
Expand All @@ -20,7 +20,7 @@
*
* @api
*/
class NullSessionStorage extends AbstractSessionStorage implements \SessionHandlerInterface
class NullSessionHandler implements \SessionHandlerInterface
{
/**
* {@inheritdoc}
Expand Down

0 comments on commit 0a064d8

Please sign in to comment.