diff --git a/cake/libs/cake_session.php b/cake/libs/cake_session.php index cc7c96211..4f97ad1ce 100644 --- a/cake/libs/cake_session.php +++ b/cake/libs/cake_session.php @@ -417,15 +417,24 @@ class CakeSession { * @param string $value Value to write * @return boolean True if the write was successful, false if the write failed */ - public static function write($name, $value) { + public static function write($name, $value = null) { if (empty($name)) { return false; } - if (in_array($name, self::$watchKeys)) { - trigger_error(sprintf(__('Writing session key {%s}: %s'), $name, Debugger::exportVar($value)), E_USER_NOTICE); + $write = $name; + if (!is_array($name)) { + $write = array($name => $value); } - self::__overwrite($_SESSION, Set::insert($_SESSION, $name, $value)); - return (Set::classicExtract($_SESSION, $name) === $value); + foreach ($write as $key => $val) { + if (in_array($key, self::$watchKeys)) { + trigger_error(sprintf(__('Writing session key {%s}: %s'), $key, Debugger::exportVar($val)), E_USER_NOTICE); + } + self::__overwrite($_SESSION, Set::insert($_SESSION, $key, $val)); + if (Set::classicExtract($_SESSION, $key) !== $val) { + return false; + } + } + return true; } /** diff --git a/cake/tests/cases/libs/cake_session.test.php b/cake/tests/cases/libs/cake_session.test.php index cf2531819..77d8b9b1c 100644 --- a/cake/tests/cases/libs/cake_session.test.php +++ b/cake/tests/cases/libs/cake_session.test.php @@ -148,6 +148,24 @@ class CakeSessionTest extends CakeTestCase { $this->assertEqual('value', $result); } +/** + * test writing a hash of values/ + * + * @return void + */ + function testWriteArray() { + $result = TestCakeSession::write(array( + 'one' => 1, + 'two' => 2, + 'three' => array('something'), + 'null' => null + )); + $this->assertTrue($result); + $this->assertEquals(1, TestCakeSession::read('one')); + $this->assertEquals(array('something'), TestCakeSession::read('three')); + $this->assertEquals(null, TestCakeSession::read('null')); + } + /** * testId method *