Permalink
Browse files

Updating Php and Cookie Session adapters to use the basename of the L…

…ITHIUM_APP_PATH by defalt.

In the future, this default may be removed so we can also completely remove the LITHIUM_APP_PATH constant.
Please refer to commit to UnionOfRAD/framework@72d6673 for proper usage.
refs #225 and #218.
  • Loading branch information...
1 parent 482af18 commit b34eda2a5d6f7df07172162682aac655893d30c6 @gwoo gwoo committed Jan 5, 2012
@@ -10,7 +10,6 @@
use RuntimeException;
use lithium\util\Set;
-use lithium\util\Inflector;
/**
* A minimal adapter to interface with HTTP cookies.
@@ -30,7 +29,7 @@ class Cookie extends \lithium\core\Object {
* strtotime-compatible string instead of an epochal timestamp.
*/
protected $_defaults = array(
- 'expire' => '+2 days', 'path' => '/', 'name' => null,
+ 'expire' => '+2 days', 'path' => '/',
'domain' => '', 'secure' => false, 'httponly' => false
);
@@ -42,20 +41,10 @@ class Cookie extends \lithium\core\Object {
* @param array $config Optional configuration parameters.
*/
public function __construct(array $config = array()) {
- parent::__construct($config + $this->_defaults);
- }
-
- /**
- * Initialization of the cookie adapter.
- *
- * @return void
- */
- protected function _init() {
- parent::_init();
-
- if (!$this->_config['name']) {
- $this->_config['name'] = Inflector::slug(basename(LITHIUM_APP_PATH)) . 'cookie';
+ if (empty($config['name'])) {
+ $config['name'] = basename(LITHIUM_APP_PATH) . 'cookie';
}
+ parent::__construct($config + $this->_defaults);
}
/**
@@ -11,7 +11,6 @@
use lithium\util\Set;
use RuntimeException;
use lithium\core\ConfigException;
-use lithium\util\Inflector;
/**
* A minimal adapter to interface with native PHP sessions.
@@ -30,7 +29,7 @@ class Php extends \lithium\core\Object {
*/
protected $_defaults = array(
'session.cookie_lifetime' => '0',
- 'session.cookie_httponly' => true,
+ 'session.cookie_httponly' => true
);
/**
@@ -42,7 +41,9 @@ 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);
+ if (empty($config['session.name'])) {
+ $config['session.name'] = basename(LITHIUM_APP_PATH);
+ }
parent::__construct($config + $this->_defaults);
}
@@ -56,11 +57,6 @@ protected function _init() {
$config = $this->_config;
unset($config['adapter'], $config['strategies'], $config['filters'], $config['init']);
- $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;
@@ -69,7 +65,6 @@ protected function _init() {
throw new ConfigException("Could not initialize the session.");
}
}
- $this->_config = $config;
}
/**
@@ -69,9 +69,8 @@ public function testInit() {
$result = ini_get('session.cookie_httponly');
$this->assertTrue(1, (integer) $result);
- $php = new Php(array(
- 'session.name' => '<>!@#.1234'
- ));
+ $name = 'this-is-a-custom-name';
+ $php = new Php(array('session.name' => $name));
$this->assertFalse(is_numeric($php->_config['session.name']));
}

0 comments on commit b34eda2

Please sign in to comment.