mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Making CakeSession::write() able to write hashes of data.
This commit is contained in:
parent
59ea917c23
commit
e660416545
2 changed files with 32 additions and 5 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue