blob: 1195ed9550aaaf951eed249523e0944c31b232d5 [file] [log] [blame]
Darren Hillc4e266b2011-08-30 15:40:27 -04001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 5.1.6 or newer
6 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
12 * @since Version 2.0
13 * @filesource
14 */
15
16
17/**
Darren Hill5073a372011-08-31 13:54:19 -040018 * CI_Session Class
Darren Hillc4e266b2011-08-30 15:40:27 -040019 *
20 * The user interface defined by EllisLabs, now with puggable drivers to manage different storage mechanisms.
dchill420e884082012-08-11 20:10:17 -040021 * By default, the cookie session driver will load, but the 'sess_driver' config/param item (see above) can be
22 * used to specify the 'native' driver, or any other you might create.
Darren Hillc4e266b2011-08-30 15:40:27 -040023 * Once loaded, this driver setup is a drop-in replacement for the former CI_Session library, taking its place as the
24 * 'session' member of the global controller framework (e.g.: $CI->session or $this->session).
25 * In keeping with the CI_Driver methodology, multiple drivers may be loaded, although this might be a bit confusing.
Darren Hill5073a372011-08-31 13:54:19 -040026 * The CI_Session library class keeps track of the most recently loaded driver as "current" to call for driver methods.
Darren Hillc4e266b2011-08-30 15:40:27 -040027 * Ideally, one driver is loaded and all calls go directly through the main library interface. However, any methods
28 * called through the specific driver will switch the "current" driver to itself before invoking the library method
29 * (which will then call back into the driver for low-level operations). So, alternation between two drivers can be
30 * achieved by specifying which driver to use for each call (e.g.: $this->session->native->set_userdata('foo', 'bar');
31 * $this->session->cookie->userdata('foo'); $this->session->native->unset_userdata('foo');). Notice in the previous
32 * example that the _native_ userdata value 'foo' would be set to 'bar', which would NOT be returned by the call for
33 * the _cookie_ userdata 'foo', nor would the _cookie_ value be unset by the call to unset the _native_ 'foo' value.
34 *
35 * @package CodeIgniter
36 * @subpackage Libraries
37 * @category Sessions
Darren Hill5073a372011-08-31 13:54:19 -040038 * @author ExpressionEngine Dev Team
Darren Hillc4e266b2011-08-30 15:40:27 -040039 * @link http://codeigniter.com/user_guide/libraries/sessions.html
40 */
Darren Hilla2ae6572011-09-01 07:36:26 -040041class CI_Session extends CI_Driver_Library {
Darren Hillc4e266b2011-08-30 15:40:27 -040042 public $params = array();
Darren Hilla2ae6572011-09-01 07:36:26 -040043 protected $current = null;
44 protected $userdata = array();
dchill423cecd822012-08-28 21:37:27 -040045 protected $loaded = array();
Darren Hillc4e266b2011-08-30 15:40:27 -040046
47 const FLASHDATA_KEY = 'flash';
48 const FLASHDATA_NEW = ':new:';
49 const FLASHDATA_OLD = ':old:';
50 const FLASHDATA_EXP = ':exp:';
51 const EXPIRATION_KEY = '__expirations';
52 const TEMP_EXP_DEF = 300;
53
54 /**
Darren Hill5073a372011-08-31 13:54:19 -040055 * CI_Session constructor
Darren Hillc4e266b2011-08-30 15:40:27 -040056 *
57 * The constructor loads the configured driver ('sess_driver' in config.php or as a parameter), running
58 * routines in its constructor, and manages flashdata aging.
59 *
Darren Hill5073a372011-08-31 13:54:19 -040060 * @param array Configuration parameters
Darren Hillc4e266b2011-08-30 15:40:27 -040061 */
62 public function __construct(array $params = array())
63 {
Darren Hill5073a372011-08-31 13:54:19 -040064 log_message('debug', 'CI_Session Class Initialized');
Darren Hillc4e266b2011-08-30 15:40:27 -040065
66 // Get valid drivers list
67 $CI =& get_instance();
dchill4226429202012-07-31 10:55:07 -040068 $this->valid_drivers = array(
69 'Session_native',
70 'Session_cookie'
71 );
Darren Hillc4e266b2011-08-30 15:40:27 -040072 $key = 'sess_valid_drivers';
73 $drivers = (isset($params[$key])) ? $params[$key] : $CI->config->item($key);
74 if ($drivers)
75 {
dchill4277ee3fd2012-07-24 11:50:01 -040076 if ( ! is_array($drivers)) $drivers = array($drivers);
Darren Hillc4e266b2011-08-30 15:40:27 -040077
78 // Add driver names to valid list
79 foreach ($drivers as $driver)
80 {
dchill4277ee3fd2012-07-24 11:50:01 -040081 if ( ! in_array(strtolower($driver), array_map('strtolower', $this->valid_drivers)))
Darren Hillc4e266b2011-08-30 15:40:27 -040082 {
83 $this->valid_drivers[] = $driver;
84 }
85 }
86 }
87
88 // Get driver to load
89 $key = 'sess_driver';
90 $driver = (isset($params[$key])) ? $params[$key] : $CI->config->item($key);
dchill4277ee3fd2012-07-24 11:50:01 -040091 if ( ! $driver) $driver = 'cookie';
92 if ( ! in_array('session_'.strtolower($driver), array_map('strtolower', $this->valid_drivers)))
Darren Hillc4e266b2011-08-30 15:40:27 -040093 {
94 $this->valid_drivers[] = 'Session_'.$driver;
95 }
96
97 // Save a copy of parameters in case drivers need access
98 $this->params = $params;
99
100 // Load driver and get array reference
101 $this->load_driver($driver);
Darren Hillc4e266b2011-08-30 15:40:27 -0400102
103 // Delete 'old' flashdata (from last request)
104 $this->_flashdata_sweep();
105
106 // Mark all new flashdata as old (data will be deleted before next request)
107 $this->_flashdata_mark();
108
109 // Delete expired tempdata
110 $this->_tempdata_sweep();
111
Darren Hill5073a372011-08-31 13:54:19 -0400112 log_message('debug', 'CI_Session routines successfully run');
Darren Hillc4e266b2011-08-30 15:40:27 -0400113 }
114
115 /**
dchill423cecd822012-08-28 21:37:27 -0400116 * CI_Session destructor
117 *
118 * The destructor calls shutdown() on each loaded driver
119 */
120 public function __destruct()
121 {
122 // Call shutdown for each loaded driver
123 foreach ($this->loaded as $driver)
124 {
125 $this->$driver->shutdown();
126 }
127
128 log_message('debug', 'CI_Session Class Shutdown');
129 }
130
131 /**
Darren Hillc4e266b2011-08-30 15:40:27 -0400132 * Loads session storage driver
133 *
Darren Hill5073a372011-08-31 13:54:19 -0400134 * @param string Driver classname
135 * @return object Loaded driver object
Darren Hillc4e266b2011-08-30 15:40:27 -0400136 */
137 public function load_driver($driver)
138 {
dchill4226429202012-07-31 10:55:07 -0400139 // Save reference to most recently loaded driver as library default and sync userdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400140 $this->current = parent::load_driver($driver);
dchill42b1855372012-07-31 09:32:23 -0400141 $this->userdata =& $this->current->get_userdata();
dchill423cecd822012-08-28 21:37:27 -0400142
143 // Mark driver as loaded
144 if (!in_array($driver, $this->loaded))
145 {
146 $this->loaded[] = $driver;
147 }
148
149 // Return driver object
Darren Hillc4e266b2011-08-30 15:40:27 -0400150 return $this->current;
151 }
152
153 /**
154 * Select default session storage driver
155 *
Darren Hill5073a372011-08-31 13:54:19 -0400156 * @param string Driver classname
157 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400158 */
159 public function select_driver($driver)
160 {
161 // Validate driver name
dchill42c5872252012-07-30 14:53:11 -0400162 $lowername = strtolower(str_replace('CI_', '', $driver));
Darren Hillc4e266b2011-08-30 15:40:27 -0400163 if (in_array($lowername, array_map('strtolower', $this->valid_drivers)))
164 {
dchill42b1855372012-07-31 09:32:23 -0400165 // See if driver is loaded
166 $child = str_replace($this->lib_name.'_', '', $driver);
167 if (isset($this->$child))
Darren Hillc4e266b2011-08-30 15:40:27 -0400168 {
dchill42aee92652012-08-26 21:45:35 -0400169 // See if driver is already current
170 if ($this->$child !== $this->current) {
171 // Make driver current and sync userdata
172 $this->current = $this->$child;
173 $this->userdata =& $this->current->get_userdata();
174 }
Darren Hillc4e266b2011-08-30 15:40:27 -0400175 }
176 else
177 {
dchill4226429202012-07-31 10:55:07 -0400178 // Load new driver
dchill42aee92652012-08-26 21:45:35 -0400179 $this->load_driver($child);
Darren Hillc4e266b2011-08-30 15:40:27 -0400180 }
181 }
182 }
183
184 /**
185 * Destroy the current session
186 *
Darren Hill5073a372011-08-31 13:54:19 -0400187 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400188 */
189 public function sess_destroy()
190 {
191 // Just call destroy on driver
192 $this->current->sess_destroy();
193 }
194
195 /**
196 * Regenerate the current session
197 *
Darren Hill5073a372011-08-31 13:54:19 -0400198 * @param boolean Destroy session data flag (default: false)
199 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400200 */
201 public function sess_regenerate($destroy = false)
202 {
dchill4226429202012-07-31 10:55:07 -0400203 // Call regenerate on driver and resync userdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400204 $this->current->sess_regenerate($destroy);
dchill4226429202012-07-31 10:55:07 -0400205 $this->userdata =& $this->current->get_userdata();
Darren Hillc4e266b2011-08-30 15:40:27 -0400206 }
207
208 /**
209 * Fetch a specific item from the session array
210 *
Darren Hill5073a372011-08-31 13:54:19 -0400211 * @param string Item key
dchill42c5872252012-07-30 14:53:11 -0400212 * @return string Item value or NULL if not found
Darren Hillc4e266b2011-08-30 15:40:27 -0400213 */
214 public function userdata($item)
215 {
dchill42c5872252012-07-30 14:53:11 -0400216 // Return value or NULL if not found
dchill4277ee3fd2012-07-24 11:50:01 -0400217 return ( ! isset($this->userdata[$item])) ? NULL : $this->userdata[$item];
Darren Hillc4e266b2011-08-30 15:40:27 -0400218 }
219
220 /**
221 * Fetch all session data
222 *
223 * @return array User data array
224 */
225 public function all_userdata()
226 {
227 // Return entire array
dchill4277ee3fd2012-07-24 11:50:01 -0400228 return ( ! isset($this->userdata)) ? NULL : $this->userdata;
Darren Hillc4e266b2011-08-30 15:40:27 -0400229 }
230
231 /**
dchill42c5079de2012-07-23 10:53:47 -0400232 * Fetch all flashdata
233 *
234 * @return array Flash data array
235 */
236 public function all_flashdata()
237 {
238 $out = array();
239
240 // loop through all userdata
241 foreach ($this->all_userdata() as $key => $val)
242 {
dchill42c5872252012-07-30 14:53:11 -0400243 // if it contains flashdata, add it
dchill42c5079de2012-07-23 10:53:47 -0400244 if (strpos($key, self::FLASHDATA_KEY.self::FLASHDATA_OLD) !== FALSE)
245 {
dchill4226429202012-07-31 10:55:07 -0400246 $key = str_replace(self::FLASHDATA_KEY.self::FLASHDATA_OLD, '', $key);
dchill42c5079de2012-07-23 10:53:47 -0400247 $out[$key] = $val;
248 }
249 }
250 return $out;
251 }
252
253 /**
Darren Hillc4e266b2011-08-30 15:40:27 -0400254 * Add or change data in the "userdata" array
255 *
Darren Hill5073a372011-08-31 13:54:19 -0400256 * @param mixed Item name or array of items
257 * @param string Item value or empty string
258 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400259 */
260 public function set_userdata($newdata = array(), $newval = '')
261 {
262 // Wrap params as array if singular
263 if (is_string($newdata))
264 {
265 $newdata = array($newdata => $newval);
266 }
267
268 // Set each name/value pair
269 if (count($newdata) > 0)
270 {
271 foreach ($newdata as $key => $val)
272 {
273 $this->userdata[$key] = $val;
274 }
275 }
276
277 // Tell driver data changed
278 $this->current->sess_save();
279 }
280
281 /**
282 * Delete a session variable from the "userdata" array
283 *
Darren Hill5073a372011-08-31 13:54:19 -0400284 * @param mixed Item name or array of item names
285 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400286 */
287 public function unset_userdata($newdata = array())
288 {
289 // Wrap single name as array
290 if (is_string($newdata))
291 {
292 $newdata = array($newdata => '');
293 }
294
295 // Unset each item name
296 if (count($newdata) > 0)
297 {
298 foreach ($newdata as $key => $val)
299 {
300 unset($this->userdata[$key]);
301 }
302 }
303
304 // Tell driver data changed
305 $this->current->sess_save();
306 }
307
308 /**
309 * Determine if an item exists
310 *
Darren Hill5073a372011-08-31 13:54:19 -0400311 * @param string Item name
312 * @return boolean
Darren Hillc4e266b2011-08-30 15:40:27 -0400313 */
314 public function has_userdata($item)
315 {
316 // Check for item name
317 return isset($this->userdata[$item]);
318 }
319
320 /**
321 * Add or change flashdata, only available until the next request
322 *
Darren Hill5073a372011-08-31 13:54:19 -0400323 * @param mixed Item name or array of items
324 * @param string Item value or empty string
325 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400326 */
327 public function set_flashdata($newdata = array(), $newval = '')
328 {
329 // Wrap item as array if singular
330 if (is_string($newdata))
331 {
332 $newdata = array($newdata => $newval);
333 }
334
335 // Prepend each key name and set value
336 if (count($newdata) > 0)
337 {
338 foreach ($newdata as $key => $val)
339 {
340 $flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_NEW.$key;
341 $this->set_userdata($flashdata_key, $val);
342 }
343 }
344 }
345
346 /**
347 * Keeps existing flashdata available to next request.
348 *
Darren Hill5073a372011-08-31 13:54:19 -0400349 * @param string Item key
350 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400351 */
352 public function keep_flashdata($key)
353 {
dchill42c5079de2012-07-23 10:53:47 -0400354 // 'old' flashdata gets removed. Here we mark all flashdata as 'new' to preserve it from _flashdata_sweep()
355 // Note the function will return NULL if the $key provided cannot be found
Darren Hillc4e266b2011-08-30 15:40:27 -0400356 $old_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key;
357 $value = $this->userdata($old_flashdata_key);
358
359 $new_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_NEW.$key;
360 $this->set_userdata($new_flashdata_key, $value);
361 }
362
363 /**
364 * Fetch a specific flashdata item from the session array
365 *
Darren Hill5073a372011-08-31 13:54:19 -0400366 * @param string Item key
367 * @return string
Darren Hillc4e266b2011-08-30 15:40:27 -0400368 */
369 public function flashdata($key)
370 {
371 // Prepend key and retrieve value
372 $flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key;
373 return $this->userdata($flashdata_key);
374 }
375
376 /**
377 * Add or change tempdata, only available
378 * until expiration
379 *
Darren Hill5073a372011-08-31 13:54:19 -0400380 * @param mixed Item name or array of items
381 * @param string Item value or empty string
382 * @param int Item lifetime in seconds or 0 for default
383 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400384 */
385 public function set_tempdata($newdata = array(), $newval = '', $expire = 0)
386 {
387 // Set expiration time
388 $expire = time() + ($expire ? $expire : self::TEMP_EXP_DEF);
389
390 // Wrap item as array if singular
391 if (is_string($newdata))
392 {
393 $newdata = array($newdata => $newval);
394 }
395
396 // Get or create expiration list
397 $expirations = $this->userdata(self::EXPIRATION_KEY);
dchill4277ee3fd2012-07-24 11:50:01 -0400398 if ( ! $expirations)
Darren Hillc4e266b2011-08-30 15:40:27 -0400399 {
400 $expirations = array();
401 }
402
403 // Prepend each key name and set value
404 if (count($newdata) > 0)
405 {
406 foreach ($newdata as $key => $val)
407 {
408 $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key;
409 $expirations[$tempdata_key] = $expire;
410 $this->set_userdata($tempdata_key, $val);
411 }
412 }
413
414 // Update expiration list
415 $this->set_userdata(self::EXPIRATION_KEY, $expirations);
416 }
417
418 /**
419 * Delete a temporary session variable from the "userdata" array
420 *
Darren Hill5073a372011-08-31 13:54:19 -0400421 * @param mixed Item name or array of item names
422 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400423 */
424 public function unset_tempdata($newdata = array())
425 {
426 // Get expirations list
427 $expirations = $this->userdata(self::EXPIRATION_KEY);
dchill4277ee3fd2012-07-24 11:50:01 -0400428 if ( ! $expirations || ! count($expirations))
Darren Hillc4e266b2011-08-30 15:40:27 -0400429 {
430 // Nothing to do
431 return;
432 }
433
434 // Wrap single name as array
435 if (is_string($newdata))
436 {
437 $newdata = array($newdata => '');
438 }
439
440 // Prepend each item name and unset
441 if (count($newdata) > 0)
442 {
443 foreach ($newdata as $key => $val)
444 {
445 $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key;
446 unset($expirations[$tempdata_key]);
447 $this->unset_userdata($tempdata_key);
448 }
449 }
450
451 // Update expiration list
452 $this->set_userdata(self::EXPIRATION_KEY, $expirations);
453 }
454
455 /**
456 * Fetch a specific tempdata item from the session array
457 *
Darren Hill5073a372011-08-31 13:54:19 -0400458 * @param string Item key
459 * @return string
Darren Hillc4e266b2011-08-30 15:40:27 -0400460 */
461 public function tempdata($key)
462 {
463 // Prepend key and return value
464 $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key;
465 return $this->userdata($tempdata_key);
466 }
467
468 /**
469 * Identifies flashdata as 'old' for removal
470 * when _flashdata_sweep() runs.
471 *
Darren Hilla2ae6572011-09-01 07:36:26 -0400472 * @access protected
Darren Hillc4e266b2011-08-30 15:40:27 -0400473 * @return void
474 */
Darren Hilla2ae6572011-09-01 07:36:26 -0400475 protected function _flashdata_mark()
Darren Hillc4e266b2011-08-30 15:40:27 -0400476 {
477 $userdata = $this->all_userdata();
478 foreach ($userdata as $name => $value)
479 {
480 $parts = explode(self::FLASHDATA_NEW, $name);
481 if (is_array($parts) && count($parts) === 2)
482 {
483 $new_name = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$parts[1];
484 $this->set_userdata($new_name, $value);
485 $this->unset_userdata($name);
486 }
487 }
488 }
489
490 /**
491 * Removes all flashdata marked as 'old'
492 *
Darren Hilla2ae6572011-09-01 07:36:26 -0400493 * @access protected
Darren Hillc4e266b2011-08-30 15:40:27 -0400494 * @return void
495 */
Darren Hilla2ae6572011-09-01 07:36:26 -0400496 protected function _flashdata_sweep()
Darren Hillc4e266b2011-08-30 15:40:27 -0400497 {
498 $userdata = $this->all_userdata();
499 foreach ($userdata as $key => $value)
500 {
501 if (strpos($key, self::FLASHDATA_OLD))
502 {
503 $this->unset_userdata($key);
504 }
505 }
506 }
507
508 /**
509 * Removes all expired tempdata
510 *
Darren Hilla2ae6572011-09-01 07:36:26 -0400511 * @access protected
Darren Hillc4e266b2011-08-30 15:40:27 -0400512 * @return void
513 */
Darren Hilla2ae6572011-09-01 07:36:26 -0400514 protected function _tempdata_sweep()
Darren Hillc4e266b2011-08-30 15:40:27 -0400515 {
516 // Get expirations list
517 $expirations = $this->userdata(self::EXPIRATION_KEY);
dchill4277ee3fd2012-07-24 11:50:01 -0400518 if ( ! $expirations || ! count($expirations))
Darren Hillc4e266b2011-08-30 15:40:27 -0400519 {
520 // Nothing to do
521 return;
522 }
523
524 // Unset expired elements
525 $now = time();
526 $userdata = $this->all_userdata();
527 foreach ($userdata as $key => $value)
528 {
529 if (strpos($key, self::FLASHDATA_EXP) && $expirations[$key] < $now)
530 {
531 unset($expirations[$key]);
532 $this->unset_userdata($key);
533 }
534 }
535
536 // Update expiration list
537 $this->set_userdata(self::EXPIRATION_KEY, $expirations);
538 }
539}
Darren Hill5073a372011-08-31 13:54:19 -0400540// END CI_Session Class
Darren Hillc4e266b2011-08-30 15:40:27 -0400541
542
543/**
Darren Hill5073a372011-08-31 13:54:19 -0400544 * CI_Session_driver Class
Darren Hillc4e266b2011-08-30 15:40:27 -0400545 *
Darren Hill5073a372011-08-31 13:54:19 -0400546 * Extend this class to make a new CI_Session driver.
547 * A CI_Session driver basically manages an array of name/value pairs with some sort of storage mechanism.
548 * To make a new driver, derive from (extend) CI_Session_driver. Overload the initialize method and read or create
Darren Hillc4e266b2011-08-30 15:40:27 -0400549 * session data. Then implement a save handler to write changed data to storage (sess_save), a destroy handler
550 * to remove deleted data (sess_destroy), and an access handler to expose the data (get_userdata).
Darren Hill5073a372011-08-31 13:54:19 -0400551 * Put your driver in the libraries/Session/drivers folder anywhere in the loader paths. This includes the
552 * application directory, the system directory, or any path you add with $CI->load->add_package_path().
553 * Your driver must be named CI_Session_<name>, and your filename must be Session_<name>.php,
554 * preferably also capitalized. (e.g.: CI_Session_foo in libraries/Session/drivers/Session_foo.php)
555 * Then specify the driver by setting 'sess_driver' in your config file or as a parameter when loading the CI_Session
Darren Hillc4e266b2011-08-30 15:40:27 -0400556 * object. (e.g.: $config['sess_driver'] = 'foo'; OR $CI->load->driver('session', array('sess_driver' => 'foo')); )
557 * Already provided are the Native driver, which manages the native PHP $_SESSION array, and
558 * the Cookie driver, which manages the data in a browser cookie, with optional extra storage in a database table.
559 *
Darren Hill5073a372011-08-31 13:54:19 -0400560 * @package CodeIgniter
561 * @subpackage Libraries
Darren Hillc4e266b2011-08-30 15:40:27 -0400562 * @category Sessions
Darren Hill5073a372011-08-31 13:54:19 -0400563 * @author ExpressionEngine Dev Team
Darren Hillc4e266b2011-08-30 15:40:27 -0400564 */
Darren Hill5073a372011-08-31 13:54:19 -0400565abstract class CI_Session_driver extends CI_Driver {
Darren Hillc4e266b2011-08-30 15:40:27 -0400566 /**
567 * Decorate
568 *
569 * Decorates the child with the parent driver lib's methods and properties
570 *
571 * @param object Parent library object
572 * @return void
573 */
574 public function decorate($parent)
575 {
576 // Call base class decorate first
577 parent::decorate($parent);
578
dchill42c5872252012-07-30 14:53:11 -0400579 // Call initialize method now that driver has access to $this->_parent
Darren Hillc4e266b2011-08-30 15:40:27 -0400580 $this->initialize();
581 }
582
583 /**
584 * __call magic method
585 *
586 * Handles access to the parent driver library's methods
587 *
Darren Hill5073a372011-08-31 13:54:19 -0400588 * @param string Library method name
589 * @param array Method arguments (default: none)
Darren Hillc4e266b2011-08-30 15:40:27 -0400590 * @return mixed
591 */
592 public function __call($method, $args = array())
593 {
594 // Make sure the parent library uses this driver
dchill42c5872252012-07-30 14:53:11 -0400595 $this->_parent->select_driver(get_class($this));
Darren Hillc4e266b2011-08-30 15:40:27 -0400596 return parent::__call($method, $args);
597 }
598
599 /**
600 * Initialize driver
601 *
Darren Hill5073a372011-08-31 13:54:19 -0400602 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400603 */
604 protected function initialize()
605 {
606 // Overload this method to implement initialization
607 }
608
609 /**
dchill423cecd822012-08-28 21:37:27 -0400610 * Shut down driver
611 *
612 * @return void
613 */
614 public function shutdown()
615 {
616 // Overload this method to implement shutdown
617 }
618
619 /**
Darren Hillc4e266b2011-08-30 15:40:27 -0400620 * Save the session data
621 *
622 * Data in the array has changed - perform any storage synchronization necessary
623 * The child class MUST implement this abstract method!
624 *
Darren Hill5073a372011-08-31 13:54:19 -0400625 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400626 */
627 abstract public function sess_save();
628
629 /**
630 * Destroy the current session
631 *
632 * Clean up storage for this session - it has been terminated
633 * The child class MUST implement this abstract method!
634 *
Darren Hill5073a372011-08-31 13:54:19 -0400635 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400636 */
637 abstract public function sess_destroy();
638
639 /**
640 * Regenerate the current session
641 *
642 * Regenerate the session id
643 * The child class MUST implement this abstract method!
644 *
Darren Hill5073a372011-08-31 13:54:19 -0400645 * @param boolean Destroy session data flag (default: false)
646 * @return void
Darren Hillc4e266b2011-08-30 15:40:27 -0400647 */
648 abstract public function sess_regenerate($destroy = false);
649
650 /**
651 * Get a reference to user data array
652 *
Darren Hill5073a372011-08-31 13:54:19 -0400653 * Give array access to the main CI_Session object
Darren Hillc4e266b2011-08-30 15:40:27 -0400654 * The child class MUST implement this abstract method!
655 *
Darren Hill5073a372011-08-31 13:54:19 -0400656 * @return array Reference to userdata
Darren Hillc4e266b2011-08-30 15:40:27 -0400657 */
658 abstract public function &get_userdata();
659}
Darren Hill5073a372011-08-31 13:54:19 -0400660// END CI_Session_driver Class
Darren Hillc4e266b2011-08-30 15:40:27 -0400661
662
663/* End of file Session.php */
664/* Location: ./system/libraries/Session/Session.php */
665?>