mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Refactoring session classes.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3958 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
d4af73c2a6
commit
1fa21aa551
5 changed files with 80 additions and 46 deletions
|
@ -37,13 +37,23 @@
|
|||
*
|
||||
*/
|
||||
class SessionComponent extends CakeSession {
|
||||
/**
|
||||
* Used to determine if methods implementation is used, or bypassed
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
var $__active = true;
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $base
|
||||
*/
|
||||
function __construct($base = null) {
|
||||
if (!defined('AUTO_SESSION') || AUTO_SESSION === true) {
|
||||
parent::__construct($base);
|
||||
} else {
|
||||
$this->__active = false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Startup method. Copies controller data locally for rendering flash messages.
|
||||
|
@ -68,8 +78,10 @@ class SessionComponent extends CakeSession {
|
|||
* @param string $value The value you want to store in a session.
|
||||
*/
|
||||
function write($name, $value) {
|
||||
if ($this->__active === true) {
|
||||
$this->writeSessionVar($name, $value);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Used to read a session values for a key or return values for all keys.
|
||||
*
|
||||
|
@ -81,8 +93,11 @@ class SessionComponent extends CakeSession {
|
|||
* @return values from the session vars
|
||||
*/
|
||||
function read($name = null) {
|
||||
if ($this->__active === true) {
|
||||
return $this->readSessionVar($name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Used to delete a session variable.
|
||||
*
|
||||
|
@ -92,8 +107,11 @@ class SessionComponent extends CakeSession {
|
|||
* @return boolean, true is session variable is set and can be deleted, false is variable was not set.
|
||||
*/
|
||||
function del($name) {
|
||||
if ($this->__active === true) {
|
||||
return $this->delSessionVar($name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Wrapper for SessionComponent::del();
|
||||
*
|
||||
|
@ -103,8 +121,11 @@ class SessionComponent extends CakeSession {
|
|||
* @return boolean, true is session variable is set and can be deleted, false is variable was not set.
|
||||
*/
|
||||
function delete($name) {
|
||||
if ($this->__active === true) {
|
||||
return $this->del($name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Used to check if a session variable is set
|
||||
*
|
||||
|
@ -114,8 +135,11 @@ class SessionComponent extends CakeSession {
|
|||
* @return boolean true is session variable is set, false if not
|
||||
*/
|
||||
function check($name) {
|
||||
if ($this->__active === true) {
|
||||
return $this->checkSessionVar($name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Used to determine the last error in a session.
|
||||
*
|
||||
|
@ -124,8 +148,11 @@ class SessionComponent extends CakeSession {
|
|||
* @return string Last session error
|
||||
*/
|
||||
function error() {
|
||||
if ($this->__active === true) {
|
||||
return $this->getLastError();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Used to set a session variable that can be used to output messages in the view.
|
||||
*
|
||||
|
@ -139,9 +166,10 @@ class SessionComponent extends CakeSession {
|
|||
* @param string $key Message key, default is 'flash'
|
||||
*/
|
||||
function setFlash($flashMessage, $layout = 'default', $params = array(), $key = 'flash') {
|
||||
if ($this->__active === true) {
|
||||
if ($layout == 'default') {
|
||||
$out = '<div id="' . $key . 'Message" class="message">' . $flashMessage . '</div>';
|
||||
} else if($layout == '' || $layout == null) {
|
||||
} elseif ($layout == '' || $layout == null) {
|
||||
$out = $flashMessage;
|
||||
} else {
|
||||
$ctrl = null;
|
||||
|
@ -161,6 +189,7 @@ class SessionComponent extends CakeSession {
|
|||
}
|
||||
$this->write('Message.' . $key, $out);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This method is deprecated.
|
||||
* You should use $session->flash('key'); in your views
|
||||
|
@ -170,21 +199,25 @@ class SessionComponent extends CakeSession {
|
|||
* @deprecated
|
||||
*/
|
||||
function flash($key = 'flash') {
|
||||
if ($this->__active === true) {
|
||||
if ($this->check('Message.' . $key)) {
|
||||
e($this->read('Message.' . $key));
|
||||
$this->del('Message.' . $key);
|
||||
} else {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Used to renew a session id
|
||||
*
|
||||
* In your controller: $this->Session->renew();
|
||||
*/
|
||||
function renew() {
|
||||
if ($this->__active === true) {
|
||||
parent::renew();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Used to check for a valid session.
|
||||
*
|
||||
|
@ -193,16 +226,21 @@ class SessionComponent extends CakeSession {
|
|||
* @return boolean true is session is valid, false is session is invalid
|
||||
*/
|
||||
function valid() {
|
||||
if ($this->__active === true) {
|
||||
return $this->isValid();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Used to destroy sessions
|
||||
*
|
||||
* In your controller:. $this->Session->destroy();
|
||||
*/
|
||||
function destroy() {
|
||||
if ($this->__active === true) {
|
||||
$this->destroyInvalid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -175,7 +175,7 @@ class Controller extends Object {
|
|||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
var $components = array();
|
||||
var $components = array('Session');
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
|
@ -258,10 +258,6 @@ class Controller extends Object {
|
|||
$this->modelClass = ucwords(Inflector::singularize($this->name));
|
||||
$this->modelKey = Inflector::underscore($this->modelClass);
|
||||
|
||||
if (!defined('AUTO_SESSION') || AUTO_SESSION == true) {
|
||||
$this->components[] = 'Session';
|
||||
}
|
||||
|
||||
if (is_subclass_of($this, 'AppController')) {
|
||||
$appVars = get_class_vars('AppController');
|
||||
|
||||
|
|
|
@ -243,7 +243,7 @@ class Scaffold extends Object{
|
|||
|
||||
if ($this->controllerClass->{$this->modelKey}->save($this->controllerClass->params['data'])) {
|
||||
if ($this->controllerClass->_afterScaffoldSave($type)) {
|
||||
if (is_object($this->controllerClass->Session)) {
|
||||
if (is_object($this->controllerClass->Session) && $this->controllerClass->Session->valid != false) {
|
||||
$this->controllerClass->Session->setFlash(
|
||||
'The ' . Inflector::humanize($this->modelKey) . ' has been ' . $success . '.');
|
||||
$this->controllerClass->redirect(
|
||||
|
@ -258,7 +258,7 @@ class Scaffold extends Object{
|
|||
return $this->controllerClass->_afterScaffoldSaveError($type);
|
||||
}
|
||||
} else {
|
||||
if (is_object($this->controllerClass->Session)) {
|
||||
if (is_object($this->controllerClass->Session) && $this->controllerClass->Session->valid != false) {
|
||||
$this->controllerClass->Session->setFlash('Please correct errors below.');
|
||||
}
|
||||
|
||||
|
@ -299,7 +299,7 @@ class Scaffold extends Object{
|
|||
$id=$params['pass'][0];
|
||||
|
||||
if ($this->controllerClass->{$this->modelKey}->del($id)) {
|
||||
if (is_object($this->controllerClass->Session)) {
|
||||
if (is_object($this->controllerClass->Session) && $this->controllerClass->Session->valid != false) {
|
||||
$this->controllerClass->Session->setFlash(
|
||||
'The ' . Inflector::humanize($this->modelKey) . ' with id: ' . $id
|
||||
. ' has been deleted.');
|
||||
|
@ -311,7 +311,7 @@ class Scaffold extends Object{
|
|||
'/' . Inflector::underscore($this->controllerClass->viewPath));
|
||||
}
|
||||
} else {
|
||||
if (is_object($this->controllerClass->Session)) {
|
||||
if (is_object($this->controllerClass->Session) && $this->controllerClass->Session->valid != false) {
|
||||
$this->controllerClass->Session->setFlash(
|
||||
'There was an error deleting the ' . Inflector::humanize($this->modelKey)
|
||||
. ' with the id ' . $id);
|
||||
|
|
|
@ -48,7 +48,7 @@ class SessionHelper extends CakeSession {
|
|||
* @param string $base
|
||||
*/
|
||||
function __construct($base = null) {
|
||||
if (!defined('AUTO_SESSION') || AUTO_SESSION == true) {
|
||||
if (!defined('AUTO_SESSION') || AUTO_SESSION === true) {
|
||||
parent::__construct($base, false);
|
||||
} else {
|
||||
$this->__active = false;
|
||||
|
|
Loading…
Reference in a new issue