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:
phpnut 2007-02-12 00:57:44 +00:00
parent 5b85b87dc3
commit 0db06d9fdb
3 changed files with 27 additions and 16 deletions

View file

@ -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.
*

View file

@ -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);
}
/**