mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 19:38:26 +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
|
* This should be in a Controller.key format for better organizing
|
||||||
* @param string $value The value you want to store in a session.
|
* @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) {
|
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.
|
* 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)) {
|
if (is_null($name)) {
|
||||||
return $this->returnSessionVars();
|
return $this->returnSessionVars();
|
||||||
}
|
}
|
||||||
if ($this->checkSessionVar($name)) {
|
if (empty($name)) {
|
||||||
$var = $this->__sessionVarNames($name);
|
|
||||||
if (empty($var)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$result = eval("return " . $var . ";");
|
$result = Set::extract($_SESSION, $name);
|
||||||
|
|
||||||
|
if (!is_null($result)) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
$this->__setError(2, "$name doesn't exist");
|
$this->__setError(2, "$name doesn't exist");
|
||||||
$return = null;
|
return null;
|
||||||
return $return;
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns all session variables.
|
* Returns all session variables.
|
||||||
|
@ -250,8 +249,7 @@ class CakeSession extends Object {
|
||||||
*/
|
*/
|
||||||
function returnSessionVars() {
|
function returnSessionVars() {
|
||||||
if (!empty($_SESSION)) {
|
if (!empty($_SESSION)) {
|
||||||
$result = eval("return \$_SESSION;");
|
return $_SESSION;
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
$this->__setError(2, "No Session vars set");
|
$this->__setError(2, "No Session vars set");
|
||||||
return false;
|
return false;
|
||||||
|
@ -268,7 +266,7 @@ class CakeSession extends Object {
|
||||||
if (empty($var)) {
|
if (empty($var)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$expression = $var . " = \$value;";
|
$expression = 'return ' . $var . " = \$value;";
|
||||||
eval ($expression);
|
eval ($expression);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue