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