8000 [2.1] Support PHP 5.4 \SessionHandler · Pull Request #3493 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[2.1] Support PHP 5.4 \SessionHandler #3493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from Mar 15, 2012
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[HttpFoundation] Refactor session handlers.
  • Loading branch information
Drak committed Mar 14, 2012
commit 0a064d8aa1432e6fd0539591fe6b151305f6970e
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
}
}
}
Original file line number Diff line number Diff line change
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);
}
}
Original file line number Diff line number Diff line change
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);
}

}
Original file line number Diff line number Diff line change
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);
}
}
Original file line number Diff line number Diff line change
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