Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #225 from joebeeson/218-session-name

PHP Session adapter modifications
  • Loading branch information...
commit 482af18f144871bf165fed84b142311d6be5a09c 2 parents 2ef8f95 + 97ef2a5
@nateabele nateabele authored
View
12 storage/session/adapter/Php.php
@@ -11,6 +11,7 @@
use lithium\util\Set;
use RuntimeException;
use lithium\core\ConfigException;
+use lithium\util\Inflector;
/**
* A minimal adapter to interface with native PHP sessions.
@@ -28,7 +29,8 @@ class Php extends \lithium\core\Object {
* @var array Keys are session ini settings, with the `session.` namespace.
*/
protected $_defaults = array(
- 'session.cookie_lifetime' => '0', 'session.cookie_httponly' => true
+ 'session.cookie_lifetime' => '0',
+ 'session.cookie_httponly' => true,
);
/**
@@ -40,6 +42,7 @@ class Php extends \lithium\core\Object {
* the `session.*` PHP ini settings here as key/value pairs.
*/
public function __construct(array $config = array()) {
+ $this->_defaults['session.name'] = basename(LITHIUM_APP_PATH);
parent::__construct($config + $this->_defaults);
}
@@ -53,9 +56,11 @@ protected function _init() {
$config = $this->_config;
unset($config['adapter'], $config['strategies'], $config['filters'], $config['init']);
- if (!isset($config['session.name'])) {
- $config['session.name'] = basename(LITHIUM_APP_PATH);
+ $config['session.name'] = Inflector::slug($config['session.name']);
+ if (is_numeric($config['session.name'])) {
+ $config['session.name'] = 'lithium' . $config['session.name'];
}
+
foreach ($config as $key => $value) {
if (strpos($key, 'session.') === false) {
continue;
@@ -64,6 +69,7 @@ protected function _init() {
throw new ConfigException("Could not initialize the session.");
}
}
+ $this->_config = $config;
}
/**
View
5 tests/cases/storage/session/adapter/PhpTest.php
@@ -68,6 +68,11 @@ public function testInit() {
$result = ini_get('session.cookie_httponly');
$this->assertTrue(1, (integer) $result);
+
+ $php = new Php(array(
+ 'session.name' => '<>!@#.1234'
+ ));
+ $this->assertFalse(is_numeric($php->_config['session.name']));
}
public function testCustomConfiguration() {
Please sign in to comment.
Something went wrong with that request. Please try again.