mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Refactoring SessionComponent::write() to allow the first param to be an array.
Removing eval() from CakeSession::returnSessionVars() and CakeSession::readSessionVar() git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4506 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
5b85b87dc3
commit
0db06d9fdb
3 changed files with 27 additions and 16 deletions
|
@ -77,11 +77,24 @@ class SessionComponent extends CakeSession {
|
|||
* This should be in a Controller.key format for better organizing
|
||||
* @param string $value The value you want to store in a session.
|
||||
*/
|
||||
function write($name, $value) {
|
||||
function write($name, $value = null) {
|
||||
if ($this->__active === true) {
|
||||
$this->writeSessionVar($name, $value);
|
||||
if(is_array($name)) {
|
||||
foreach($name as $key => $value) {
|
||||
if ($this->writeSessionVar($key, $value) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if ($this->writeSessionVar($name, $value) === false) {
|
||||
die(debug($this));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Used to read a session values for a key or return values for all keys.
|
||||
*
|
||||
|
|
|
@ -230,17 +230,16 @@ class CakeSession extends Object {
|
|||
if (is_null($name)) {
|
||||
return $this->returnSessionVars();
|
||||
}
|
||||
if ($this->checkSessionVar($name)) {
|
||||
$var = $this->__sessionVarNames($name);
|
||||
if (empty($var)) {
|
||||
if (empty($name)) {
|
||||
return false;
|
||||
}
|
||||
$result = eval("return " . $var . ";");
|
||||
$result = Set::extract($_SESSION, $name);
|
||||
|
||||
if (!is_null($result)) {
|
||||
return $result;
|
||||
}
|
||||
$this->__setError(2, "$name doesn't exist");
|
||||
$return = null;
|
||||
return $return;
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Returns all session variables.
|
||||
|
@ -250,8 +249,7 @@ class CakeSession extends Object {
|
|||
*/
|
||||
function returnSessionVars() {
|
||||
if (!empty($_SESSION)) {
|
||||
$result = eval("return \$_SESSION;");
|
||||
return $result;
|
||||
return $_SESSION;
|
||||
}
|
||||
$this->__setError(2, "No Session vars set");
|
||||
return false;
|
||||
|
@ -268,7 +266,7 @@ class CakeSession extends Object {
|
|||
if (empty($var)) {
|
||||
return false;
|
||||
}
|
||||
$expression = $var . " = \$value;";
|
||||
$expression = 'return ' . $var . " = \$value;";
|
||||
eval ($expression);
|
||||
}
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue