Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
| 6 | * |
| 7 | * NOTICE OF LICENSE |
| 8 | * |
| 9 | * Licensed under the Open Software License version 3.0 |
| 10 | * |
| 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 18 | * |
| 19 | * @package CodeIgniter |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Andrey Andreev | 80500af | 2013-01-01 08:16:53 +0200 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 2.0 |
| 25 | * @filesource |
| 26 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 27 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 28 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 29 | /** |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 30 | * CodeIgniter Session Class |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 31 | * |
| 32 | * The user interface defined by EllisLabs, now with puggable drivers to manage different storage mechanisms. |
dchill42 | 0e88408 | 2012-08-11 20:10:17 -0400 | [diff] [blame] | 33 | * By default, the cookie session driver will load, but the 'sess_driver' config/param item (see above) can be |
| 34 | * used to specify the 'native' driver, or any other you might create. |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 35 | * Once loaded, this driver setup is a drop-in replacement for the former CI_Session library, taking its place as the |
| 36 | * 'session' member of the global controller framework (e.g.: $CI->session or $this->session). |
| 37 | * In keeping with the CI_Driver methodology, multiple drivers may be loaded, although this might be a bit confusing. |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 38 | * The CI_Session library class keeps track of the most recently loaded driver as "current" to call for driver methods. |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 39 | * Ideally, one driver is loaded and all calls go directly through the main library interface. However, any methods |
| 40 | * called through the specific driver will switch the "current" driver to itself before invoking the library method |
| 41 | * (which will then call back into the driver for low-level operations). So, alternation between two drivers can be |
| 42 | * achieved by specifying which driver to use for each call (e.g.: $this->session->native->set_userdata('foo', 'bar'); |
| 43 | * $this->session->cookie->userdata('foo'); $this->session->native->unset_userdata('foo');). Notice in the previous |
| 44 | * example that the _native_ userdata value 'foo' would be set to 'bar', which would NOT be returned by the call for |
| 45 | * the _cookie_ userdata 'foo', nor would the _cookie_ value be unset by the call to unset the _native_ 'foo' value. |
| 46 | * |
| 47 | * @package CodeIgniter |
| 48 | * @subpackage Libraries |
| 49 | * @category Sessions |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 50 | * @author EllisLab Dev Team |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 51 | * @link http://codeigniter.com/user_guide/libraries/sessions.html |
| 52 | */ |
Darren Hill | a2ae657 | 2011-09-01 07:36:26 -0400 | [diff] [blame] | 53 | class CI_Session extends CI_Driver_Library { |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 54 | |
Andrey Andreev | 0fa95bd | 2012-11-01 23:33:14 +0200 | [diff] [blame] | 55 | /** |
| 56 | * Initialization parameters |
| 57 | * |
| 58 | * @var array |
| 59 | */ |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 60 | public $params = array(); |
Andrey Andreev | 0fa95bd | 2012-11-01 23:33:14 +0200 | [diff] [blame] | 61 | |
| 62 | /** |
Andrey Andreev | c958eeb | 2013-07-31 14:28:50 +0300 | [diff] [blame] | 63 | * Valid drivers list |
| 64 | * |
| 65 | * @var array |
| 66 | */ |
| 67 | public $valid_drivers = array('native', 'cookie'); |
| 68 | |
| 69 | /** |
Andrey Andreev | 0fa95bd | 2012-11-01 23:33:14 +0200 | [diff] [blame] | 70 | * Current driver in use |
| 71 | * |
| 72 | * @var string |
| 73 | */ |
Andrey Andreev | c958eeb | 2013-07-31 14:28:50 +0300 | [diff] [blame] | 74 | public $current = NULL; |
Andrey Andreev | 0fa95bd | 2012-11-01 23:33:14 +0200 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * User data |
| 78 | * |
| 79 | * @var array |
| 80 | */ |
Darren Hill | a2ae657 | 2011-09-01 07:36:26 -0400 | [diff] [blame] | 81 | protected $userdata = array(); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 82 | |
Andrey Andreev | 0fa95bd | 2012-11-01 23:33:14 +0200 | [diff] [blame] | 83 | // ------------------------------------------------------------------------ |
| 84 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 85 | const FLASHDATA_KEY = 'flash'; |
| 86 | const FLASHDATA_NEW = ':new:'; |
| 87 | const FLASHDATA_OLD = ':old:'; |
| 88 | const FLASHDATA_EXP = ':exp:'; |
| 89 | const EXPIRATION_KEY = '__expirations'; |
| 90 | const TEMP_EXP_DEF = 300; |
| 91 | |
Andrey Andreev | 0fa95bd | 2012-11-01 23:33:14 +0200 | [diff] [blame] | 92 | // ------------------------------------------------------------------------ |
| 93 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 94 | /** |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 95 | * CI_Session constructor |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 96 | * |
| 97 | * The constructor loads the configured driver ('sess_driver' in config.php or as a parameter), running |
| 98 | * routines in its constructor, and manages flashdata aging. |
| 99 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 100 | * @param array Configuration parameters |
Andrey Andreev | 2e3e230 | 2012-10-09 15:52:34 +0300 | [diff] [blame] | 101 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 102 | */ |
| 103 | public function __construct(array $params = array()) |
| 104 | { |
Andrey Andreev | f964b16 | 2013-11-12 17:04:55 +0200 | [diff] [blame^] | 105 | $_config =& get_instance()->config; |
Andrey Andreev | 2e3e230 | 2012-10-09 15:52:34 +0300 | [diff] [blame] | 106 | |
| 107 | // No sessions under CLI |
Andrey Andreev | f964b16 | 2013-11-12 17:04:55 +0200 | [diff] [blame^] | 108 | if (is_cli()) |
Andrey Andreev | 2e3e230 | 2012-10-09 15:52:34 +0300 | [diff] [blame] | 109 | { |
| 110 | return; |
| 111 | } |
| 112 | |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 113 | log_message('debug', 'CI_Session Class Initialized'); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 114 | |
Andrey Andreev | c958eeb | 2013-07-31 14:28:50 +0300 | [diff] [blame] | 115 | // Add possible extra entries to our valid drivers list |
Andrey Andreev | f964b16 | 2013-11-12 17:04:55 +0200 | [diff] [blame^] | 116 | $drivers = isset($params['sess_valid_drivers']) ? $params['sess_valid_drivers'] : $_config->item('sess_valid_drivers'); |
Andrey Andreev | c958eeb | 2013-07-31 14:28:50 +0300 | [diff] [blame] | 117 | if ( ! empty($drivers)) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 118 | { |
Andrey Andreev | c958eeb | 2013-07-31 14:28:50 +0300 | [diff] [blame] | 119 | $drivers = array_map('strtolower', (array) $drivers); |
| 120 | $this->valid_drivers = array_merge($this->valid_drivers, array_diff($drivers, $this->valid_drivers)); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | // Get driver to load |
Andrey Andreev | f964b16 | 2013-11-12 17:04:55 +0200 | [diff] [blame^] | 124 | $driver = isset($params['sess_driver']) ? $params['sess_driver'] : $_config->item('sess_driver'); |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 125 | if ( ! $driver) |
| 126 | { |
Andrey Andreev | c958eeb | 2013-07-31 14:28:50 +0300 | [diff] [blame] | 127 | log_message('debug', "Session: No driver name is configured, defaulting to 'cookie'."); |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 128 | $driver = 'cookie'; |
| 129 | } |
| 130 | |
Andrey Andreev | c958eeb | 2013-07-31 14:28:50 +0300 | [diff] [blame] | 131 | if ( ! in_array($driver, $this->valid_drivers)) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 132 | { |
Andrey Andreev | c958eeb | 2013-07-31 14:28:50 +0300 | [diff] [blame] | 133 | log_message('error', 'Session: Configured driver name is not valid, aborting.'); |
| 134 | return; |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | // Save a copy of parameters in case drivers need access |
| 138 | $this->params = $params; |
| 139 | |
| 140 | // Load driver and get array reference |
| 141 | $this->load_driver($driver); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 142 | |
| 143 | // Delete 'old' flashdata (from last request) |
| 144 | $this->_flashdata_sweep(); |
| 145 | |
| 146 | // Mark all new flashdata as old (data will be deleted before next request) |
| 147 | $this->_flashdata_mark(); |
| 148 | |
| 149 | // Delete expired tempdata |
| 150 | $this->_tempdata_sweep(); |
| 151 | |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 152 | log_message('debug', 'CI_Session routines successfully run'); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 153 | } |
| 154 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 155 | // ------------------------------------------------------------------------ |
| 156 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 157 | /** |
| 158 | * Loads session storage driver |
| 159 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 160 | * @param string Driver classname |
| 161 | * @return object Loaded driver object |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 162 | */ |
| 163 | public function load_driver($driver) |
| 164 | { |
dchill42 | 2642920 | 2012-07-31 10:55:07 -0400 | [diff] [blame] | 165 | // Save reference to most recently loaded driver as library default and sync userdata |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 166 | $this->current = parent::load_driver($driver); |
dchill42 | b185537 | 2012-07-31 09:32:23 -0400 | [diff] [blame] | 167 | $this->userdata =& $this->current->get_userdata(); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 168 | return $this->current; |
| 169 | } |
| 170 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 171 | // ------------------------------------------------------------------------ |
| 172 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 173 | /** |
| 174 | * Select default session storage driver |
| 175 | * |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 176 | * @param string Driver name |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 177 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 178 | */ |
| 179 | public function select_driver($driver) |
| 180 | { |
| 181 | // Validate driver name |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 182 | $prefix = (string) get_instance()->config->item('subclass_prefix'); |
| 183 | $child = strtolower(str_replace(array('CI_', $prefix, $this->lib_name.'_'), '', $driver)); |
| 184 | if (in_array($child, array_map('strtolower', $this->valid_drivers))) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 185 | { |
dchill42 | b185537 | 2012-07-31 09:32:23 -0400 | [diff] [blame] | 186 | // See if driver is loaded |
dchill42 | b185537 | 2012-07-31 09:32:23 -0400 | [diff] [blame] | 187 | if (isset($this->$child)) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 188 | { |
dchill42 | aee9265 | 2012-08-26 21:45:35 -0400 | [diff] [blame] | 189 | // See if driver is already current |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 190 | if ($this->$child !== $this->current) |
| 191 | { |
dchill42 | aee9265 | 2012-08-26 21:45:35 -0400 | [diff] [blame] | 192 | // Make driver current and sync userdata |
| 193 | $this->current = $this->$child; |
| 194 | $this->userdata =& $this->current->get_userdata(); |
| 195 | } |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 196 | } |
| 197 | else |
| 198 | { |
dchill42 | 2642920 | 2012-07-31 10:55:07 -0400 | [diff] [blame] | 199 | // Load new driver |
dchill42 | aee9265 | 2012-08-26 21:45:35 -0400 | [diff] [blame] | 200 | $this->load_driver($child); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 205 | // ------------------------------------------------------------------------ |
| 206 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 207 | /** |
| 208 | * Destroy the current session |
| 209 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 210 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 211 | */ |
| 212 | public function sess_destroy() |
| 213 | { |
| 214 | // Just call destroy on driver |
| 215 | $this->current->sess_destroy(); |
| 216 | } |
| 217 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 218 | // ------------------------------------------------------------------------ |
| 219 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 220 | /** |
| 221 | * Regenerate the current session |
| 222 | * |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 223 | * @param bool Destroy session data flag (default: false) |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 224 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 225 | */ |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 226 | public function sess_regenerate($destroy = FALSE) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 227 | { |
dchill42 | 2642920 | 2012-07-31 10:55:07 -0400 | [diff] [blame] | 228 | // Call regenerate on driver and resync userdata |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 229 | $this->current->sess_regenerate($destroy); |
dchill42 | 2642920 | 2012-07-31 10:55:07 -0400 | [diff] [blame] | 230 | $this->userdata =& $this->current->get_userdata(); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 231 | } |
| 232 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 233 | // ------------------------------------------------------------------------ |
| 234 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 235 | /** |
| 236 | * Fetch a specific item from the session array |
| 237 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 238 | * @param string Item key |
dchill42 | c587225 | 2012-07-30 14:53:11 -0400 | [diff] [blame] | 239 | * @return string Item value or NULL if not found |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 240 | */ |
| 241 | public function userdata($item) |
| 242 | { |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 243 | return isset($this->userdata[$item]) ? $this->userdata[$item] : NULL; |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 244 | } |
| 245 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 246 | // ------------------------------------------------------------------------ |
| 247 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 248 | /** |
| 249 | * Fetch all session data |
| 250 | * |
| 251 | * @return array User data array |
| 252 | */ |
| 253 | public function all_userdata() |
| 254 | { |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 255 | return isset($this->userdata) ? $this->userdata : NULL; |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 256 | } |
| 257 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 258 | // ------------------------------------------------------------------------ |
| 259 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 260 | /** |
dchill42 | c5079de | 2012-07-23 10:53:47 -0400 | [diff] [blame] | 261 | * Fetch all flashdata |
| 262 | * |
vkeranov | 3bb4029 | 2012-10-27 18:47:26 +0300 | [diff] [blame] | 263 | * @return array Flash data array |
dchill42 | c5079de | 2012-07-23 10:53:47 -0400 | [diff] [blame] | 264 | */ |
| 265 | public function all_flashdata() |
| 266 | { |
| 267 | $out = array(); |
| 268 | |
| 269 | // loop through all userdata |
| 270 | foreach ($this->all_userdata() as $key => $val) |
| 271 | { |
dchill42 | c587225 | 2012-07-30 14:53:11 -0400 | [diff] [blame] | 272 | // if it contains flashdata, add it |
dchill42 | c5079de | 2012-07-23 10:53:47 -0400 | [diff] [blame] | 273 | if (strpos($key, self::FLASHDATA_KEY.self::FLASHDATA_OLD) !== FALSE) |
| 274 | { |
dchill42 | 2642920 | 2012-07-31 10:55:07 -0400 | [diff] [blame] | 275 | $key = str_replace(self::FLASHDATA_KEY.self::FLASHDATA_OLD, '', $key); |
dchill42 | c5079de | 2012-07-23 10:53:47 -0400 | [diff] [blame] | 276 | $out[$key] = $val; |
| 277 | } |
| 278 | } |
| 279 | return $out; |
| 280 | } |
| 281 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 282 | // ------------------------------------------------------------------------ |
| 283 | |
dchill42 | c5079de | 2012-07-23 10:53:47 -0400 | [diff] [blame] | 284 | /** |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 285 | * Add or change data in the "userdata" array |
| 286 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 287 | * @param mixed Item name or array of items |
| 288 | * @param string Item value or empty string |
| 289 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 290 | */ |
| 291 | public function set_userdata($newdata = array(), $newval = '') |
| 292 | { |
| 293 | // Wrap params as array if singular |
| 294 | if (is_string($newdata)) |
| 295 | { |
| 296 | $newdata = array($newdata => $newval); |
| 297 | } |
| 298 | |
| 299 | // Set each name/value pair |
| 300 | if (count($newdata) > 0) |
| 301 | { |
| 302 | foreach ($newdata as $key => $val) |
| 303 | { |
| 304 | $this->userdata[$key] = $val; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | // Tell driver data changed |
| 309 | $this->current->sess_save(); |
| 310 | } |
| 311 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 312 | // ------------------------------------------------------------------------ |
| 313 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 314 | /** |
| 315 | * Delete a session variable from the "userdata" array |
| 316 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 317 | * @param mixed Item name or array of item names |
| 318 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 319 | */ |
| 320 | public function unset_userdata($newdata = array()) |
| 321 | { |
| 322 | // Wrap single name as array |
| 323 | if (is_string($newdata)) |
| 324 | { |
| 325 | $newdata = array($newdata => ''); |
| 326 | } |
| 327 | |
| 328 | // Unset each item name |
| 329 | if (count($newdata) > 0) |
| 330 | { |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 331 | foreach (array_keys($newdata) as $key) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 332 | { |
| 333 | unset($this->userdata[$key]); |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | // Tell driver data changed |
| 338 | $this->current->sess_save(); |
| 339 | } |
| 340 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 341 | // ------------------------------------------------------------------------ |
| 342 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 343 | /** |
| 344 | * Determine if an item exists |
| 345 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 346 | * @param string Item name |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 347 | * @return bool |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 348 | */ |
| 349 | public function has_userdata($item) |
| 350 | { |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 351 | return isset($this->userdata[$item]); |
| 352 | } |
| 353 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 354 | // ------------------------------------------------------------------------ |
| 355 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 356 | /** |
| 357 | * Add or change flashdata, only available until the next request |
| 358 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 359 | * @param mixed Item name or array of items |
| 360 | * @param string Item value or empty string |
| 361 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 362 | */ |
| 363 | public function set_flashdata($newdata = array(), $newval = '') |
| 364 | { |
| 365 | // Wrap item as array if singular |
| 366 | if (is_string($newdata)) |
| 367 | { |
| 368 | $newdata = array($newdata => $newval); |
| 369 | } |
| 370 | |
| 371 | // Prepend each key name and set value |
| 372 | if (count($newdata) > 0) |
| 373 | { |
| 374 | foreach ($newdata as $key => $val) |
| 375 | { |
| 376 | $flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_NEW.$key; |
| 377 | $this->set_userdata($flashdata_key, $val); |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 382 | // ------------------------------------------------------------------------ |
| 383 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 384 | /** |
| 385 | * Keeps existing flashdata available to next request. |
| 386 | * |
Johnathan Croom | 9d9849b | 2012-11-24 13:03:13 -0700 | [diff] [blame] | 387 | * @param mixed Item key(s) |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 388 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 389 | */ |
| 390 | public function keep_flashdata($key) |
| 391 | { |
Johnathan Croom | 8d8543d | 2012-11-25 10:36:57 -0700 | [diff] [blame] | 392 | |
| 393 | if (is_array($key)) |
Johnathan Croom | 4beca5c | 2012-11-23 18:32:46 -0700 | [diff] [blame] | 394 | { |
Johnathan Croom | 8d8543d | 2012-11-25 10:36:57 -0700 | [diff] [blame] | 395 | foreach ($key as $k) |
| 396 | { |
| 397 | $this->keep_flashdata($k); |
| 398 | } |
| 399 | |
| 400 | return; |
Johnathan Croom | 4beca5c | 2012-11-23 18:32:46 -0700 | [diff] [blame] | 401 | } |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 402 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 403 | // 'old' flashdata gets removed. Here we mark all flashdata as 'new' to preserve it from _flashdata_sweep() |
| 404 | // Note the function will return NULL if the $key provided cannot be found |
| 405 | $old_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key; |
| 406 | $value = $this->userdata($old_flashdata_key); |
| 407 | |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 408 | $new_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_NEW.$key; |
| 409 | $this->set_userdata($new_flashdata_key, $value); |
| 410 | } |
| 411 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 412 | // ------------------------------------------------------------------------ |
| 413 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 414 | /** |
| 415 | * Fetch a specific flashdata item from the session array |
| 416 | * |
| 417 | * @param string Item key |
| 418 | * @return string |
| 419 | */ |
| 420 | public function flashdata($key) |
| 421 | { |
| 422 | // Prepend key and retrieve value |
| 423 | $flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key; |
| 424 | return $this->userdata($flashdata_key); |
| 425 | } |
| 426 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 427 | // ------------------------------------------------------------------------ |
| 428 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 429 | /** |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 430 | * Add or change tempdata, only available until expiration |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 431 | * |
| 432 | * @param mixed Item name or array of items |
| 433 | * @param string Item value or empty string |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 434 | * @param int Item lifetime in seconds or 0 for default |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 435 | * @return void |
| 436 | */ |
| 437 | public function set_tempdata($newdata = array(), $newval = '', $expire = 0) |
| 438 | { |
| 439 | // Set expiration time |
| 440 | $expire = time() + ($expire ? $expire : self::TEMP_EXP_DEF); |
| 441 | |
| 442 | // Wrap item as array if singular |
| 443 | if (is_string($newdata)) |
| 444 | { |
| 445 | $newdata = array($newdata => $newval); |
| 446 | } |
| 447 | |
| 448 | // Get or create expiration list |
| 449 | $expirations = $this->userdata(self::EXPIRATION_KEY); |
dchill42 | 77ee3fd | 2012-07-24 11:50:01 -0400 | [diff] [blame] | 450 | if ( ! $expirations) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 451 | { |
| 452 | $expirations = array(); |
| 453 | } |
| 454 | |
| 455 | // Prepend each key name and set value |
| 456 | if (count($newdata) > 0) |
| 457 | { |
| 458 | foreach ($newdata as $key => $val) |
| 459 | { |
| 460 | $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key; |
| 461 | $expirations[$tempdata_key] = $expire; |
| 462 | $this->set_userdata($tempdata_key, $val); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | // Update expiration list |
| 467 | $this->set_userdata(self::EXPIRATION_KEY, $expirations); |
| 468 | } |
| 469 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 470 | // ------------------------------------------------------------------------ |
| 471 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 472 | /** |
| 473 | * Delete a temporary session variable from the "userdata" array |
| 474 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 475 | * @param mixed Item name or array of item names |
| 476 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 477 | */ |
| 478 | public function unset_tempdata($newdata = array()) |
| 479 | { |
| 480 | // Get expirations list |
| 481 | $expirations = $this->userdata(self::EXPIRATION_KEY); |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 482 | if (empty($expirations)) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 483 | { |
| 484 | // Nothing to do |
| 485 | return; |
| 486 | } |
| 487 | |
| 488 | // Wrap single name as array |
| 489 | if (is_string($newdata)) |
| 490 | { |
| 491 | $newdata = array($newdata => ''); |
| 492 | } |
| 493 | |
| 494 | // Prepend each item name and unset |
| 495 | if (count($newdata) > 0) |
| 496 | { |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 497 | foreach (array_keys($newdata) as $key) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 498 | { |
| 499 | $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key; |
| 500 | unset($expirations[$tempdata_key]); |
| 501 | $this->unset_userdata($tempdata_key); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | // Update expiration list |
| 506 | $this->set_userdata(self::EXPIRATION_KEY, $expirations); |
| 507 | } |
| 508 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 509 | // ------------------------------------------------------------------------ |
| 510 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 511 | /** |
| 512 | * Fetch a specific tempdata item from the session array |
| 513 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 514 | * @param string Item key |
| 515 | * @return string |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 516 | */ |
| 517 | public function tempdata($key) |
| 518 | { |
| 519 | // Prepend key and return value |
| 520 | $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key; |
| 521 | return $this->userdata($tempdata_key); |
| 522 | } |
| 523 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 524 | // ------------------------------------------------------------------------ |
| 525 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 526 | /** |
| 527 | * Identifies flashdata as 'old' for removal |
| 528 | * when _flashdata_sweep() runs. |
| 529 | * |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 530 | * @return void |
| 531 | */ |
Darren Hill | a2ae657 | 2011-09-01 07:36:26 -0400 | [diff] [blame] | 532 | protected function _flashdata_mark() |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 533 | { |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 534 | foreach ($this->all_userdata() as $name => $value) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 535 | { |
| 536 | $parts = explode(self::FLASHDATA_NEW, $name); |
Andrey Andreev | e24eed7 | 2012-11-02 23:33:45 +0200 | [diff] [blame] | 537 | if (count($parts) === 2) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 538 | { |
| 539 | $new_name = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$parts[1]; |
| 540 | $this->set_userdata($new_name, $value); |
| 541 | $this->unset_userdata($name); |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 546 | // ------------------------------------------------------------------------ |
| 547 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 548 | /** |
| 549 | * Removes all flashdata marked as 'old' |
| 550 | * |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 551 | * @return void |
| 552 | */ |
Darren Hill | a2ae657 | 2011-09-01 07:36:26 -0400 | [diff] [blame] | 553 | protected function _flashdata_sweep() |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 554 | { |
| 555 | $userdata = $this->all_userdata(); |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 556 | foreach (array_keys($userdata) as $key) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 557 | { |
| 558 | if (strpos($key, self::FLASHDATA_OLD)) |
| 559 | { |
| 560 | $this->unset_userdata($key); |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 565 | // ------------------------------------------------------------------------ |
| 566 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 567 | /** |
| 568 | * Removes all expired tempdata |
| 569 | * |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 570 | * @return void |
| 571 | */ |
Darren Hill | a2ae657 | 2011-09-01 07:36:26 -0400 | [diff] [blame] | 572 | protected function _tempdata_sweep() |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 573 | { |
| 574 | // Get expirations list |
| 575 | $expirations = $this->userdata(self::EXPIRATION_KEY); |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 576 | if (empty($expirations)) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 577 | { |
| 578 | // Nothing to do |
| 579 | return; |
| 580 | } |
| 581 | |
| 582 | // Unset expired elements |
| 583 | $now = time(); |
| 584 | $userdata = $this->all_userdata(); |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 585 | foreach (array_keys($userdata) as $key) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 586 | { |
| 587 | if (strpos($key, self::FLASHDATA_EXP) && $expirations[$key] < $now) |
| 588 | { |
| 589 | unset($expirations[$key]); |
| 590 | $this->unset_userdata($key); |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | // Update expiration list |
| 595 | $this->set_userdata(self::EXPIRATION_KEY, $expirations); |
| 596 | } |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 597 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | // ------------------------------------------------------------------------ |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 601 | |
| 602 | /** |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 603 | * CI_Session_driver Class |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 604 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 605 | * Extend this class to make a new CI_Session driver. |
| 606 | * A CI_Session driver basically manages an array of name/value pairs with some sort of storage mechanism. |
| 607 | * To make a new driver, derive from (extend) CI_Session_driver. Overload the initialize method and read or create |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 608 | * session data. Then implement a save handler to write changed data to storage (sess_save), a destroy handler |
| 609 | * to remove deleted data (sess_destroy), and an access handler to expose the data (get_userdata). |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 610 | * Put your driver in the libraries/Session/drivers folder anywhere in the loader paths. This includes the |
| 611 | * application directory, the system directory, or any path you add with $CI->load->add_package_path(). |
| 612 | * Your driver must be named CI_Session_<name>, and your filename must be Session_<name>.php, |
| 613 | * preferably also capitalized. (e.g.: CI_Session_foo in libraries/Session/drivers/Session_foo.php) |
| 614 | * Then specify the driver by setting 'sess_driver' in your config file or as a parameter when loading the CI_Session |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 615 | * object. (e.g.: $config['sess_driver'] = 'foo'; OR $CI->load->driver('session', array('sess_driver' => 'foo')); ) |
| 616 | * Already provided are the Native driver, which manages the native PHP $_SESSION array, and |
| 617 | * the Cookie driver, which manages the data in a browser cookie, with optional extra storage in a database table. |
| 618 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 619 | * @package CodeIgniter |
| 620 | * @subpackage Libraries |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 621 | * @category Sessions |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 622 | * @author EllisLab Dev Team |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 623 | */ |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 624 | abstract class CI_Session_driver extends CI_Driver { |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 625 | |
Andrey Andreev | 0fa95bd | 2012-11-01 23:33:14 +0200 | [diff] [blame] | 626 | /** |
| 627 | * CI Singleton |
| 628 | * |
| 629 | * @see get_instance() |
| 630 | * @var object |
| 631 | */ |
Andrey Andreev | 2e3e230 | 2012-10-09 15:52:34 +0300 | [diff] [blame] | 632 | protected $CI; |
| 633 | |
Andrey Andreev | 0fa95bd | 2012-11-01 23:33:14 +0200 | [diff] [blame] | 634 | // ------------------------------------------------------------------------ |
| 635 | |
Andrey Andreev | 2e3e230 | 2012-10-09 15:52:34 +0300 | [diff] [blame] | 636 | /** |
| 637 | * Constructor |
| 638 | * |
| 639 | * Gets the CI singleton, so that individual drivers |
| 640 | * don't have to do it separately. |
| 641 | * |
| 642 | * @return void |
| 643 | */ |
| 644 | public function __construct() |
| 645 | { |
| 646 | $this->CI =& get_instance(); |
| 647 | } |
| 648 | |
| 649 | // ------------------------------------------------------------------------ |
| 650 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 651 | /** |
| 652 | * Decorate |
| 653 | * |
| 654 | * Decorates the child with the parent driver lib's methods and properties |
| 655 | * |
| 656 | * @param object Parent library object |
| 657 | * @return void |
| 658 | */ |
| 659 | public function decorate($parent) |
| 660 | { |
| 661 | // Call base class decorate first |
| 662 | parent::decorate($parent); |
| 663 | |
dchill42 | c587225 | 2012-07-30 14:53:11 -0400 | [diff] [blame] | 664 | // Call initialize method now that driver has access to $this->_parent |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 665 | $this->initialize(); |
| 666 | } |
| 667 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 668 | // ------------------------------------------------------------------------ |
| 669 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 670 | /** |
| 671 | * __call magic method |
| 672 | * |
| 673 | * Handles access to the parent driver library's methods |
| 674 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 675 | * @param string Library method name |
| 676 | * @param array Method arguments (default: none) |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 677 | * @return mixed |
| 678 | */ |
| 679 | public function __call($method, $args = array()) |
| 680 | { |
| 681 | // Make sure the parent library uses this driver |
dchill42 | c587225 | 2012-07-30 14:53:11 -0400 | [diff] [blame] | 682 | $this->_parent->select_driver(get_class($this)); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 683 | return parent::__call($method, $args); |
| 684 | } |
| 685 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 686 | // ------------------------------------------------------------------------ |
| 687 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 688 | /** |
| 689 | * Initialize driver |
| 690 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 691 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 692 | */ |
| 693 | protected function initialize() |
| 694 | { |
| 695 | // Overload this method to implement initialization |
| 696 | } |
| 697 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 698 | // ------------------------------------------------------------------------ |
| 699 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 700 | /** |
| 701 | * Save the session data |
| 702 | * |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 703 | * Data in the array has changed - perform any storage synchronization |
| 704 | * necessary. The child class MUST implement this abstract method! |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 705 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 706 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 707 | */ |
| 708 | abstract public function sess_save(); |
| 709 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 710 | // ------------------------------------------------------------------------ |
| 711 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 712 | /** |
| 713 | * Destroy the current session |
| 714 | * |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 715 | * Clean up storage for this session - it has been terminated. |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 716 | * The child class MUST implement this abstract method! |
| 717 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 718 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 719 | */ |
| 720 | abstract public function sess_destroy(); |
| 721 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 722 | // ------------------------------------------------------------------------ |
| 723 | |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 724 | /** |
| 725 | * Regenerate the current session |
| 726 | * |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 727 | * Regenerate the session ID. |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 728 | * The child class MUST implement this abstract method! |
| 729 | * |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 730 | * @param bool Destroy session data flag (default: false) |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 731 | * @return void |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 732 | */ |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 733 | abstract public function sess_regenerate($destroy = FALSE); |
| 734 | |
| 735 | // ------------------------------------------------------------------------ |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 736 | |
| 737 | /** |
| 738 | * Get a reference to user data array |
| 739 | * |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 740 | * Give array access to the main CI_Session object. |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 741 | * The child class MUST implement this abstract method! |
| 742 | * |
Darren Hill | 5073a37 | 2011-08-31 13:54:19 -0400 | [diff] [blame] | 743 | * @return array Reference to userdata |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 744 | */ |
| 745 | abstract public function &get_userdata(); |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 746 | |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 747 | } |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 748 | |
| 749 | /* End of file Session.php */ |
Andrey Andreev | 9ffcee6 | 2012-09-05 16:25:16 +0300 | [diff] [blame] | 750 | /* Location: ./system/libraries/Session/Session.php */ |