cakephp2-php8/cake/libs/controller/components/session.php

245 lines
5.9 KiB
PHP
Raw Normal View History

<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
Merging: Revision: [1638] removing php short tags Revision: [1637] Remove renderElememnts loading of helpers also, forgot it in the last commit Revision: [1636] Refactoring after profiling code. Session was creating a new instance of Dispatcher removed the need for it. Added a check to the Component class to pass the base to the SessionComponent class, will refactor that at a later time. Changed View class so it would not load helpers when rending a layout, no need for that. A great performance boost after the change. Change the loadModels method call in app/webroot/index.php. Will only attempt the loadModels call if the AppModel class is not in memory, and the Database class is in memory. Removed all unnecessary calls to basics uses(). Again another big performance increase. Added fix to the Html::guiListTree() after discussing the output that is expected. A ticket was closed on this already. Revision: [1635] Removing calls to basic uses() Revision: [1634] Removing calls to basics uses() that are not needed. Revision: [1633] Removing calls to basics uses() that are not needed. Moved Object class further up in the loading order Revision: [1632] adding fix for Ticket #132 Revision: [1631] Added fix from Ticket #122 Revision: [1630] Scaffold views can now be placed in a view directory. These will override the core. Example (Must have the scaffold dot name): app/views/posts/scaffold.list.thtml app/views/posts/scaffold.new.thtml app/views/posts/scaffold.edit.thtml app/views/posts/scaffold.show.thtml Revision: [1629] Think I fixed the issue with scaffold showing proper dates prior to January 1 1970 00:00:00. Revision: [1628] Added a few more change to allow saving dates prior to January 1 1970 00:00:00. Still a few issues with this, but will get them figured out soon. Changed scaffold to use only one form view. Revision: [1627] Added fix for Ticket #189 Revision: [1626] Added fix for Ticket #120. Revision: [1625] left justified doc blocks Revision: [1624] remove files from uses() that are loaded by default in app/webroot/index.php no reason to attempt to load them again in the classes Revision: [1623] adding check to the loadModels and loadController that will only attempt to load files if the classes are not already in memory Revision: [1622] Adding fix to time helper that was lost in a previous merge Removing all tabs from code Revision: [1621] Addtional model validation fixes Revision: [1620] fixed parse error Revision: [1619] Fixing ticket #102 Revision: [1618] correcting mime types and keywords Revision: [1617] correcting mime types and keywords Revision: [1616] fixed link in footer Revision: [1615] Fixing ticket #207 git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1639 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-12-27 03:33:44 +00:00
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
Merging: Revision: [1638] removing php short tags Revision: [1637] Remove renderElememnts loading of helpers also, forgot it in the last commit Revision: [1636] Refactoring after profiling code. Session was creating a new instance of Dispatcher removed the need for it. Added a check to the Component class to pass the base to the SessionComponent class, will refactor that at a later time. Changed View class so it would not load helpers when rending a layout, no need for that. A great performance boost after the change. Change the loadModels method call in app/webroot/index.php. Will only attempt the loadModels call if the AppModel class is not in memory, and the Database class is in memory. Removed all unnecessary calls to basics uses(). Again another big performance increase. Added fix to the Html::guiListTree() after discussing the output that is expected. A ticket was closed on this already. Revision: [1635] Removing calls to basic uses() Revision: [1634] Removing calls to basics uses() that are not needed. Revision: [1633] Removing calls to basics uses() that are not needed. Moved Object class further up in the loading order Revision: [1632] adding fix for Ticket #132 Revision: [1631] Added fix from Ticket #122 Revision: [1630] Scaffold views can now be placed in a view directory. These will override the core. Example (Must have the scaffold dot name): app/views/posts/scaffold.list.thtml app/views/posts/scaffold.new.thtml app/views/posts/scaffold.edit.thtml app/views/posts/scaffold.show.thtml Revision: [1629] Think I fixed the issue with scaffold showing proper dates prior to January 1 1970 00:00:00. Revision: [1628] Added a few more change to allow saving dates prior to January 1 1970 00:00:00. Still a few issues with this, but will get them figured out soon. Changed scaffold to use only one form view. Revision: [1627] Added fix for Ticket #189 Revision: [1626] Added fix for Ticket #120. Revision: [1625] left justified doc blocks Revision: [1624] remove files from uses() that are loaded by default in app/webroot/index.php no reason to attempt to load them again in the classes Revision: [1623] adding check to the loadModels and loadController that will only attempt to load files if the classes are not already in memory Revision: [1622] Adding fix to time helper that was lost in a previous merge Removing all tabs from code Revision: [1621] Addtional model validation fixes Revision: [1620] fixed parse error Revision: [1619] Fixing ticket #102 Revision: [1618] correcting mime types and keywords Revision: [1617] correcting mime types and keywords Revision: [1616] fixed link in footer Revision: [1615] Fixing ticket #207 git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1639 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-12-27 03:33:44 +00:00
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.libs.controller.components
* @since CakePHP(tm) v 0.10.0.1232
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
uses('session');
/**
* Session Component.
*
* Session handling from the controller.
*
* @package cake
* @subpackage cake.cake.libs.controller.components
*
*/
class SessionComponent extends CakeSession {
/**
* Used to determine if methods implementation is used, or bypassed
*
* @var boolean
* @access private
*/
var $__active = true;
/**
* Class constructor
*
* @param string $base
*/
function __construct($base = null) {
if (Configure::read('Session.start') === true) {
parent::__construct($base);
} else {
$this->__active = false;
}
}
/**
* Turn sessions on if 'Session.start' is set to false in core.php
*
* @param string $base
*/
function activate($base = null) {
if ($this->__active === true) {
return;
}
parent::__construct($base);
$this->__active = true;
}
/**
* Startup method. Copies controller data locally for rendering flash messages.
*
* @param object $controller
* @access public
*/
function startup(&$controller) {
$this->base = $controller->base;
$this->webroot = $controller->webroot;
$this->here = $controller->here;
$this->params = $controller->params;
$this->action = $controller->action;
$this->data = $controller->data;
$this->plugin = $controller->plugin;
}
/**
* Used to write a value to a session key.
*
* In your controller: $this->Session->write('Controller.sessKey', 'session value');
*
* @param string $name The name of the key your are setting in the session.
* This should be in a Controller.key format for better organizing
* @param string $value The value you want to store in a session.
* @access public
*/
function write($name, $value = null) {
if ($this->__active === true) {
if (is_array($name)) {
foreach ($name as $key => $value) {
if (parent::write($key, $value) === false) {
return false;
}
}
return true;
}
if (parent::write($name, $value) === false) {
return false;
}
return true;
}
return false;
}
/**
* Used to read a session values for a key or return values for all keys.
*
* In your controller: $this->Session->read('Controller.sessKey');
* Calling the method without a param will return all session vars
*
* @param string $name the name of the session key you want to read
*
* @return values from the session vars
* @access public
*/
function read($name = null) {
if ($this->__active === true) {
return parent::read($name);
}
return false;
}
/**
* Used to delete a session variable.
*
* In your controller: $this->Session->del('Controller.sessKey');
*
* @param string $name
* @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 parent::del($name);
}
return false;
}
Merging fixes and enhancements into trunk. Revision: [2087] Removed array setting that is not needed Revision: [2086] Added unbindModel to turn off associations on the fly. These are reset after a call to a find<*> method. Added one more level key to isset check in DboSource::conditions. Previous check would always return true. Revision: [2085] Refactored DboSource::fields() Revision: [2084] Added fix for Ticket #419 Revision: [2083] Refactoring DboSource::conditions. Revision: [2082] Deleted a few methods by accident adding them back Revision: [2081] Added fix for Ticket #420 Added $startQuote and $endQuote vars to the MySql class, these must be added to each Dbo<database> if the database uses a quote char around fields. Example MySql uses this ` MSSQL uses [ and ]. Revision: [2080] Added delete() alias for del() in Model and SessionComponent classes. This is suggestion from Ticket #421 Revision: [2079] Added fix for Ticket #106. This was added before but lost in a merge. This fix allows adding a custom tags.ini.php file to app/config. This file will be merged with the core, overwriting any keys that match, and adding those that do not. Revision: [2078] Refactoring DboSource::conditions(). This method will now return the Model.field properly when passed a string. You can also set you own clause. WHERE, GROUP BY, HAVING, and ORDER BY. If one of these in not the first characters in the string, WHERE will be added by deafult. git-svn-id: https://svn.cakephp.org/repo/trunk/cake@2088 3807eeeb-6ff5-0310-8944-8be069107fe0
2006-02-22 09:15:12 +00:00
/**
* Wrapper for SessionComponent::del();
*
* In your controller: $this->Session->delete('Controller.sessKey');
*
* @param string $name
* @return boolean, true is session variable is set and can be deleted, false is variable was not set.
* @access public
Merging fixes and enhancements into trunk. Revision: [2087] Removed array setting that is not needed Revision: [2086] Added unbindModel to turn off associations on the fly. These are reset after a call to a find<*> method. Added one more level key to isset check in DboSource::conditions. Previous check would always return true. Revision: [2085] Refactored DboSource::fields() Revision: [2084] Added fix for Ticket #419 Revision: [2083] Refactoring DboSource::conditions. Revision: [2082] Deleted a few methods by accident adding them back Revision: [2081] Added fix for Ticket #420 Added $startQuote and $endQuote vars to the MySql class, these must be added to each Dbo<database> if the database uses a quote char around fields. Example MySql uses this ` MSSQL uses [ and ]. Revision: [2080] Added delete() alias for del() in Model and SessionComponent classes. This is suggestion from Ticket #421 Revision: [2079] Added fix for Ticket #106. This was added before but lost in a merge. This fix allows adding a custom tags.ini.php file to app/config. This file will be merged with the core, overwriting any keys that match, and adding those that do not. Revision: [2078] Refactoring DboSource::conditions(). This method will now return the Model.field properly when passed a string. You can also set you own clause. WHERE, GROUP BY, HAVING, and ORDER BY. If one of these in not the first characters in the string, WHERE will be added by deafult. git-svn-id: https://svn.cakephp.org/repo/trunk/cake@2088 3807eeeb-6ff5-0310-8944-8be069107fe0
2006-02-22 09:15:12 +00:00
*/
function delete($name) {
if ($this->__active === true) {
return $this->del($name);
}
return false;
}
/**
* Used to check if a session variable is set
*
* In your controller: $this->Session->check('Controller.sessKey');
*
* @param string $name
* @return boolean true is session variable is set, false if not
* @access public
*/
function check($name) {
if ($this->__active === true) {
return parent::check($name);
}
return false;
}
/**
* Used to determine the last error in a session.
*
* In your controller: $this->Session->error();
*
* @return string Last session error
* @access public
*/
function error() {
if ($this->__active === true) {
return parent::error();
}
return false;
}
/**
* Used to set a session variable that can be used to output messages in the view.
*
* In your controller: $this->Session->setFlash('This has been saved');
*
* Additional params below can be passed to customize the output, or the Message.[key]
*
* @param string $message Message to be flashed
* @param string $layout Layout to wrap flash message in
* @param array $params Parameters to be sent to layout as view variables
* @param string $key Message key, default is 'flash'
* @access public
*/
function setFlash($message, $layout = 'default', $params = array(), $key = 'flash') {
if ($this->__active === true) {
$this->write('Message.' . $key, compact('message', 'layout', 'params'));
}
}
/**
* Used to renew a session id
*
* In your controller: $this->Session->renew();
* @access public
*/
function renew() {
if ($this->__active === true) {
parent::renew();
}
}
/**
* Used to check for a valid session.
*
* In your controller: $this->Session->valid();
*
* @return boolean true is session is valid, false is session is invalid
* @access public
*/
function valid() {
if ($this->__active === true) {
return parent::valid();
}
return false;
}
/**
* Used to destroy sessions
*
* In your controller:. $this->Session->destroy();
* @access public
*/
function destroy() {
if ($this->__active === true) {
parent::destroy();
}
}
}
?>