Skip to content

Commit

Permalink
Disable Session library under CLI and create a CI singleton to be use…
Browse files Browse the repository at this point in the history
…d by its drivers
  • Loading branch information
narfbg committed Oct 9, 2012
1 parent 683b34d commit 2e3e230
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
4 changes: 2 additions & 2 deletions system/libraries/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CI_Driver_Library {
* @return object Child class
*/
public function __get($child)
{
{
// Try to load the driver
return $this->load_driver($child);
}
Expand Down Expand Up @@ -284,4 +284,4 @@ public function __set($var, $val)
}

/* End of file Driver.php */
/* Location: ./system/libraries/Driver.php */
/* Location: ./system/libraries/Driver.php */
27 changes: 26 additions & 1 deletion system/libraries/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,21 @@ class CI_Session extends CI_Driver_Library {
* routines in its constructor, and manages flashdata aging.
*
* @param array Configuration parameters
* @return void
*/
public function __construct(array $params = array())
{
$CI =& get_instance();

// No sessions under CLI
if ($CI->input->is_cli_request())
{
return;
}

log_message('debug', 'CI_Session Class Initialized');

// Get valid drivers list
$CI =& get_instance();
$this->valid_drivers = array(
'Session_native',
'Session_cookie'
Expand Down Expand Up @@ -587,6 +595,23 @@ protected function _tempdata_sweep()
*/
abstract class CI_Session_driver extends CI_Driver {

protected $CI;

/**
* Constructor
*
* Gets the CI singleton, so that individual drivers
* don't have to do it separately.
*
* @return void
*/
public function __construct()
{
$this->CI =& get_instance();
}

// ------------------------------------------------------------------------

/**
* Decorate
*
Expand Down
10 changes: 0 additions & 10 deletions system/libraries/Session/drivers/Session_cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,6 @@ class CI_Session_cookie extends CI_Session_driver {
*/
public $userdata = array();

/**
* Reference to CodeIgniter instance
*
* @var object
*/
public $CI;

/**
* Current time
*
Expand Down Expand Up @@ -197,9 +190,6 @@ class CI_Session_cookie extends CI_Session_driver {
*/
protected function initialize()
{
// Set the super object to a local variable for use throughout the class
$this->CI =& get_instance();

// Set all the session preferences, which can either be set
// manually via the $params array or via the config file
$prefs = array(
Expand Down
11 changes: 5 additions & 6 deletions system/libraries/Session/drivers/Session_native.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ protected function initialize()
{
// Get config parameters
$config = array();
$CI =& get_instance();
$prefs = array(
'sess_cookie_name',
'sess_expire_on_close',
Expand All @@ -63,7 +62,7 @@ protected function initialize()
{
$config[$key] = isset($this->_parent->params[$key])
? $this->_parent->params[$key]
: $CI->config->item($key);
: $this->CI->config->item($key);
}

// Set session name, if specified
Expand Down Expand Up @@ -114,13 +113,13 @@ protected function initialize()
$destroy = TRUE;
}
elseif ($config['sess_match_ip'] === TRUE && isset($_SESSION['ip_address'])
&& $_SESSION['ip_address'] !== $CI->input->ip_address())
&& $_SESSION['ip_address'] !== $this->CI->input->ip_address())
{
// IP doesn't match - destroy
$destroy = TRUE;
}
elseif ($config['sess_match_useragent'] === TRUE && isset($_SESSION['user_agent'])
&& $_SESSION['user_agent'] !== trim(substr($CI->input->user_agent(), 0, 50)))
&& $_SESSION['user_agent'] !== trim(substr($this->CI->input->user_agent(), 0, 50)))
{
// Agent doesn't match - destroy
$destroy = TRUE;
Expand Down Expand Up @@ -149,13 +148,13 @@ protected function initialize()
if ($config['sess_match_ip'] === TRUE && ! isset($_SESSION['ip_address']))
{
// Store user IP address
$_SESSION['ip_address'] = $CI->input->ip_address();
$_SESSION['ip_address'] = $this->CI->input->ip_address();
}

if ($config['sess_match_useragent'] === TRUE && ! isset($_SESSION['user_agent']))
{
// Store user agent string
$_SESSION['user_agent'] = trim(substr($CI->input->user_agent(), 0, 50));
$_SESSION['user_agent'] = trim(substr($this->CI->input->user_agent(), 0, 50));
}

// Make session ID available
Expand Down

0 comments on commit 2e3e230

Please sign in to comment.