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

@ -274,10 +274,10 @@ class AuthComponent extends Object {
$valid = $this->Acl->check($this->user(), $this->action());
break;
case 'objects':
break;
case 'association':
break;
case null:
case false:
@ -486,7 +486,7 @@ class AuthComponent extends Object {
$user = new $model();
}
}
if (empty($user)) {
if (PHP5) {
$user = ClassRegistry::getObject($this->userModel);

View file

@ -77,10 +77,23 @@ 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)) {
return false;
}
$result = eval("return " . $var . ";");
if (empty($name)) {
return false;
}
$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);
}
/**