Merging changes from 1.1.x.x CakeSession

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4210 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-12-26 13:46:22 +00:00
parent bebbfc8ff7
commit c3e2c6b3d7
2 changed files with 67 additions and 35 deletions

View file

@ -417,7 +417,7 @@ class Router extends Overloadable {
$skip = array('action', 'controller', 'plugin', 'ext', '?'); $skip = array('action', 'controller', 'plugin', 'ext', '?');
if(defined('CAKE_ADMIN')) { if(defined('CAKE_ADMIN')) {
$skip[] = CAKE_ADMIN; $skip[] = CAKE_ADMIN;
} }
$keys = array_values(array_diff(array_keys($url), $skip)); $keys = array_values(array_diff(array_keys($url), $skip));
$count = count($keys); $count = count($keys);
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
@ -444,7 +444,7 @@ class Router extends Overloadable {
$combined = join('/', $named); $combined = join('/', $named);
} }
if ($match === false) { if ($match === false) {
$urlOut = array_filter(array($url['plugin'], $url['controller'], $url['action'], join('/', array_filter($args)), $combined)); $urlOut = array_filter(array($url['plugin'], $url['controller'], $url['action'], join('/', array_filter($args)), $combined));
if($url['plugin'] == $url['controller']) { if($url['plugin'] == $url['controller']) {
@ -523,7 +523,7 @@ class Router extends Overloadable {
} else { } else {
return false; return false;
} }
/*if (!empty($diffs)) { /*if (!empty($diffs)) {
if (isset($route[3]['controller']) && in_array('controller', $diffed)) { if (isset($route[3]['controller']) && in_array('controller', $diffed)) {
return false; return false;
@ -562,7 +562,7 @@ class Router extends Overloadable {
} elseif (!isset($params['pass'])) { } elseif (!isset($params['pass'])) {
$params['pass'] = ''; $params['pass'] = '';
} }
if (strpos($route[0], '*')) { if (strpos($route[0], '*')) {
$out = str_replace('*', $params['pass'], $route[0]); $out = str_replace('*', $params['pass'], $route[0]);
} else { } else {
@ -576,7 +576,7 @@ class Router extends Overloadable {
$skip = array('action', 'controller', 'plugin', 'ext', '?', 'pass'); $skip = array('action', 'controller', 'plugin', 'ext', '?', 'pass');
if(defined('CAKE_ADMIN')) { if(defined('CAKE_ADMIN')) {
$skip[] = CAKE_ADMIN; $skip[] = CAKE_ADMIN;
} }
$args = array(); $args = array();
$keys = array_values(array_diff(array_keys($params), $skip)); $keys = array_values(array_diff(array_keys($params), $skip));
$count = count($keys); $count = count($keys);

View file

@ -36,6 +36,10 @@
if (!defined('CAKE_SESSION_TABLE')) { if (!defined('CAKE_SESSION_TABLE')) {
define('CAKE_SESSION_TABLE', 'cake_sessions'); define('CAKE_SESSION_TABLE', 'cake_sessions');
} }
if (CAKE_SESSION_SAVE === 'database') {
uses('model' . DS . 'connection_manager');
}
/** /**
* Session class for Cake. * Session class for Cake.
* *
@ -45,59 +49,69 @@
* @package cake * @package cake
* @subpackage cake.cake.libs * @subpackage cake.cake.libs
*/ */
class CakeSession extends Object{ class CakeSession extends Object {
/** /**
* True if the Session is still valid * True if the Session is still valid
* *
* @var boolean * @var boolean
* @access public
*/ */
var $valid = false; var $valid = false;
/** /**
* Error messages for this session * Error messages for this session
* *
* @var array * @var array
* @access public
*/ */
var $error = false; var $error = false;
/** /**
* User agent string * User agent string
* *
* @var string * @var string
* @access protected
*/ */
var $_userAgent = false; var $_userAgent = false;
/** /**
* Path to where the session is active. * Path to where the session is active.
* *
* @var string * @var string
* @access public
*/ */
var $path = false; var $path = false;
/** /**
* Error number of last occurred error * Error number of last occurred error
* *
* @var integer * @var integer
* @access public
*/ */
var $lastError = null; var $lastError = null;
/** /**
* CAKE_SECURITY setting, "high", "medium", or "low". * CAKE_SECURITY setting, "high", "medium", or "low".
* *
* @var string * @var string
* @access public
*/ */
var $security = null; var $security = null;
/** /**
* Start time for this session. * Start time for this session.
* *
* @var integer * @var integer
* @access public
*/ */
var $time = false; var $time = false;
/** /**
* Time when this session becomes invalid. * Time when this session becomes invalid.
* *
* @var integer * @var integer
* @access public
*/ */
var $sessionTime = false; var $sessionTime = false;
/** /**
* Constructor. * Constructor.
* *
* @param string $base The base path for the Session * @param string $base The base path for the Session
* @param boolean $start
* @access public
*/ */
function __construct($base = null, $start = true) { function __construct($base = null, $start = true) {
if($start === true) { if($start === true) {
@ -140,6 +154,7 @@ class CakeSession extends Object{
* *
* @param string $name Variable name to check for * @param string $name Variable name to check for
* @return boolean True if variable is there * @return boolean True if variable is there
* @access public
*/ */
function checkSessionVar($name) { function checkSessionVar($name) {
$expression = "return isset(" . $this->__sessionVarNames($name) . ");"; $expression = "return isset(" . $this->__sessionVarNames($name) . ");";
@ -150,6 +165,7 @@ class CakeSession extends Object{
* *
* @param string $name Session variable to remove * @param string $name Session variable to remove
* @return boolean Success * @return boolean Success
* @access public
*/ */
function delSessionVar($name) { function delSessionVar($name) {
if ($this->checkSessionVar($name)) { if ($this->checkSessionVar($name)) {
@ -165,6 +181,7 @@ class CakeSession extends Object{
* *
* @param int $errorNumber * @param int $errorNumber
* @return string Error as string * @return string Error as string
* @access public
*/ */
function getError($errorNumber) { function getError($errorNumber) {
if (!is_array($this->error) || !array_key_exists($errorNumber, $this->error)) { if (!is_array($this->error) || !array_key_exists($errorNumber, $this->error)) {
@ -177,6 +194,7 @@ class CakeSession extends Object{
* Returns last occurred error as a string, if any. * Returns last occurred error as a string, if any.
* *
* @return mixed Error description as a string, or false. * @return mixed Error description as a string, or false.
* @access public
*/ */
function getLastError() { function getLastError() {
if ($this->lastError) { if ($this->lastError) {
@ -189,6 +207,7 @@ class CakeSession extends Object{
* Returns true if session is valid. * Returns true if session is valid.
* *
* @return boolean * @return boolean
* @access public
*/ */
function isValid() { function isValid() {
return $this->valid; return $this->valid;
@ -196,8 +215,9 @@ class CakeSession extends Object{
/** /**
* Returns given session variable, or all of them, if no parameters given. * Returns given session variable, or all of them, if no parameters given.
* *
* @param mixed $name * @param mixed $name The name of the session variable
* @return unknown * @return mixed The value of the session variable
* @access public
*/ */
function readSessionVar($name = null) { function readSessionVar($name = null) {
if (is_null($name)) { if (is_null($name)) {
@ -215,6 +235,7 @@ class CakeSession extends Object{
* Returns all session variables. * Returns all session variables.
* *
* @return mixed Full $_SESSION array, or false on error. * @return mixed Full $_SESSION array, or false on error.
* @access public
*/ */
function returnSessionVars() { function returnSessionVars() {
if (!empty($_SESSION)) { if (!empty($_SESSION)) {
@ -229,6 +250,7 @@ class CakeSession extends Object{
* *
* @param mixed $name * @param mixed $name
* @param string $value * @param string $value
* @return void
*/ */
function writeSessionVar($name, $value) { function writeSessionVar($name, $value) {
$expression = $this->__sessionVarNames($name); $expression = $this->__sessionVarNames($name);
@ -236,18 +258,21 @@ class CakeSession extends Object{
eval ($expression); eval ($expression);
} }
/** /**
* Enter description here... * Method called on close of a database
* session
* *
* @return boolean
* @access private * @access private
*/ */
function __close() { function __close() {
return true; return true;
} }
/** /**
* Enter description here... * Method called on the destruction of a
* database session
* *
* @param unknown_type $key * @param integer $key
* @return unknown * @return boolean
* @access private * @access private
*/ */
function __destroy($key) { function __destroy($key) {
@ -257,8 +282,9 @@ class CakeSession extends Object{
return true; return true;
} }
/** /**
* Private helper method to destroy invalid sessions. * Helper method to destroy invalid sessions.
* *
* @return void
* @access private * @access private
*/ */
function destroyInvalid() { function destroyInvalid() {
@ -277,10 +303,11 @@ class CakeSession extends Object{
$this->renew(); $this->renew();
} }
/** /**
* Enter description here... * Helper function called on gc for
* database sessions
* *
* @param unknown_type $expires * @param unknown_type $expires
* @return unknown * @return boolean
* @access private * @access private
*/ */
function __gc($expires) { function __gc($expires) {
@ -290,8 +317,9 @@ class CakeSession extends Object{
return true; return true;
} }
/** /**
* Private helper method to initialize a session, based on Cake core settings. * Helper method to initialize a session, based on Cake core settings.
* *
* @return void
* @access private * @access private
*/ */
function __initSession() { function __initSession() {
@ -373,8 +401,9 @@ class CakeSession extends Object{
} }
} }
/** /**
* Private helper method to create a new session. * Helper method to create a new session.
* *
* @return void
* @access private * @access private
* *
*/ */
@ -398,8 +427,10 @@ class CakeSession extends Object{
} }
} }
/** /**
* Enter description here... To be implemented. * Method called on open of a database
* sesson
* *
* @return boolean
* @access private * @access private
* *
*/ */
@ -407,10 +438,11 @@ class CakeSession extends Object{
return true; return true;
} }
/** /**
* Enter description here... * Method used to read from a database
* session
* *
* @param unknown_type $key * @param mixed $key The key of the value to read
* @return unknown * @return mixed The value of the key or false if it does not exist
* @access private * @access private
*/ */
function __read($key) { function __read($key) {
@ -429,11 +461,10 @@ class CakeSession extends Object{
} }
} }
/** /**
* Private helper method to restart a session. * Helper method to restart a session.
*
* *
* @return void
* @access private * @access private
*
*/ */
function __regenerateId() { function __regenerateId() {
$oldSessionId = session_id(); $oldSessionId = session_id();
@ -461,18 +492,18 @@ class CakeSession extends Object{
/** /**
* Restarts this session. * Restarts this session.
* *
* @return void
* @access public * @access public
*
*/ */
function renew() { function renew() {
$this->__regenerateId(); $this->__regenerateId();
} }
/** /**
* Private helper method to extract variable names. * Helper method to extract variable names from the session
* variable
* *
* @param mixed $name Variable names as array or string. * @param mixed $name Variable names as array or string.
* @return string * @return string The expression to eval to get the value or false
* @access private * @access private
*/ */
function __sessionVarNames($name) { function __sessionVarNames($name) {
@ -493,10 +524,11 @@ class CakeSession extends Object{
return false; return false;
} }
/** /**
* Private helper method to set an internal error message. * Helper method to set an internal error message.
* *
* @param int $errorNumber Number of the error * @param int $errorNumber Number of the error
* @param string $errorMessage Description of the error * @param string $errorMessage Description of the error
* @return void
* @access private * @access private
*/ */
function __setError($errorNumber, $errorMessage) { function __setError($errorNumber, $errorMessage) {
@ -507,16 +539,17 @@ class CakeSession extends Object{
$this->lastError = $errorNumber; $this->lastError = $errorNumber;
} }
/** /**
* Enter description here... * Helper function called on write for database
* sessions
* *
* @param unknown_type $key * @param mixed $key The name of the var
* @param unknown_type $value * @param mixed $value The value of the var
* @return unknown * @return boolean
* @access private * @access private
*/ */
function __write($key, $value) { function __write($key, $value) {
$db =& ConnectionManager::getDataSource('default'); $db =& ConnectionManager::getDataSource('default');
$table = $db->fullTableName(CAKE_SESSION_TABLE, false); $table = $db->fullTableName(CAKE_SESSION_TABLE);
switch(CAKE_SECURITY) { switch(CAKE_SECURITY) {
case 'high': case 'high':
@ -551,5 +584,4 @@ class CakeSession extends Object{
return true; return true;
} }
} }
?> ?>