Skip to content

Commit

Permalink
Fixing an issue where strategies were applied to incorrect session co…
Browse files Browse the repository at this point in the history
…nfigurations
  • Loading branch information
rmarscher committed May 31, 2012
1 parent 9511c05 commit 606d376
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
25 changes: 13 additions & 12 deletions storage/Session.php
Expand Up @@ -147,16 +147,17 @@ public static function write($key, $value = null, array $options = array()) {
} }
} }
$result = false; $result = false;
$settings = static::_config($name);


if ($options['strategies']) { $original = $value;
$options += array('key' => $key, 'class' => __CLASS__);
$value = static::applyStrategies(__FUNCTION__, $name, $value, $options);
}
$params = compact('key', 'value', 'options');


foreach ($methods as $name => $method) { foreach ($methods as $name => $method) {
$settings = static::_config($name);
$filters = $settings['filters']; $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; $result = static::_filter(__FUNCTION__, $params, $method, $filters) || $result;
} }
return $result; return $result;
Expand Down Expand Up @@ -192,15 +193,15 @@ public static function delete($key, array $options = array()) {
} }
$result = false; $result = false;
$options += array('key' => $key, 'class' => __CLASS__); $options += array('key' => $key, 'class' => __CLASS__);

$original = $key;
if ($options['strategies']) {
$options += array('key' => $key, 'class' => __CLASS__);
$key = static::applyStrategies(__FUNCTION__, $name, $key, $options);
}
$params = compact('key', 'options');


foreach ($methods as $name => $method) { foreach ($methods as $name => $method) {
$settings = static::_config($name); $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']; $filters = $settings['filters'];
$result = static::_filter(__FUNCTION__, $params, $method, $filters) || $result; $result = static::_filter(__FUNCTION__, $params, $method, $filters) || $result;
} }
Expand Down
25 changes: 25 additions & 0 deletions tests/cases/storage/SessionTest.php
Expand Up @@ -246,6 +246,31 @@ public function testStrategies() {
$this->assertFalse(Session::check('test', array('strategies' => false))); $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() { public function testEncryptedStrategy() {
$this->skipIf(!MockEncrypt::enabled(), 'The Mcrypt extension is not installed or enabled.'); $this->skipIf(!MockEncrypt::enabled(), 'The Mcrypt extension is not installed or enabled.');


Expand Down

0 comments on commit 606d376

Please sign in to comment.