Permalink
Browse files

Fixing an issue where strategies were applied to incorrect session co…

…nfigurations
  • Loading branch information...
1 parent 9511c05 commit 606d3761aa4813029055dfddd9e2842f591073a4 @rmarscher rmarscher committed May 31, 2012
Showing with 38 additions and 12 deletions.
  1. +13 −12 storage/Session.php
  2. +25 −0 tests/cases/storage/SessionTest.php
View
@@ -147,16 +147,17 @@ public static function write($key, $value = null, array $options = array()) {
}
}
$result = false;
- $settings = static::_config($name);
- if ($options['strategies']) {
- $options += array('key' => $key, 'class' => __CLASS__);
- $value = static::applyStrategies(__FUNCTION__, $name, $value, $options);
- }
- $params = compact('key', 'value', 'options');
+ $original = $value;
foreach ($methods as $name => $method) {
+ $settings = static::_config($name);
$filters = $settings['filters'];
+ if ($options['strategies']) {
+ $options += array('key' => $key, 'class' => __CLASS__);
+ $value = static::applyStrategies(__FUNCTION__, $name, $original, $options);
+ }
+ $params = compact('key', 'value', 'options');
$result = static::_filter(__FUNCTION__, $params, $method, $filters) || $result;
}
return $result;
@@ -192,15 +193,15 @@ public static function delete($key, array $options = array()) {
}
$result = false;
$options += array('key' => $key, 'class' => __CLASS__);
-
- if ($options['strategies']) {
- $options += array('key' => $key, 'class' => __CLASS__);
- $key = static::applyStrategies(__FUNCTION__, $name, $key, $options);
- }
- $params = compact('key', 'options');
+ $original = $key;
foreach ($methods as $name => $method) {
$settings = static::_config($name);
+ if ($options['strategies']) {
+ $options += array('key' => $key, 'class' => __CLASS__);
+ $key = static::applyStrategies(__FUNCTION__, $name, $original, $options);
+ }
+ $params = compact('key', 'options');
$filters = $settings['filters'];
$result = static::_filter(__FUNCTION__, $params, $method, $filters) || $result;
}
@@ -246,6 +246,31 @@ public function testStrategies() {
$this->assertFalse(Session::check('test', array('strategies' => false)));
}
+ public function testMultipleStrategies() {
+ Session::config(array(
+ 'primary' => array(
+ 'adapter' => new Memory(),
+ 'filters' => array(),
+ 'strategies' => array()
+ ),
+ 'secondary' => array(
+ 'adapter' => new Memory(),
+ 'filters' => array(),
+ 'strategies' => array('lithium\storage\cache\strategy\Json')
+ )
+ ));
+
+ Session::write('test', array('foo' => 'bar'));
+ $result = Session::read('test');
+ $this->assertEqual(array('foo' => 'bar'), $result);
+
+ $result = Session::read('test', array('name' => 'primary', 'strategies' => false));
+ $this->assertEqual(array('foo' => 'bar'), $result);
+
+ $result = Session::read('test', array('name' => 'secondary', 'strategies' => false));
+ $this->assertEqual('{"foo":"bar"}', $result);
+ }
+
public function testEncryptedStrategy() {
$this->skipIf(!MockEncrypt::enabled(), 'The Mcrypt extension is not installed or enabled.');

0 comments on commit 606d376

Please sign in to comment.