Permalink
Browse files

Disable Session library under CLI and create a CI singleton to be use…

…d by its drivers
  • Loading branch information...
1 parent 683b34d commit 2e3e23053d9748c68fa2c0e11f43af67da8743e8 @narfbg narfbg committed Oct 9, 2012
@@ -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);
}
@@ -284,4 +284,4 @@ public function __set($var, $val)
}
/* End of file Driver.php */
-/* Location: ./system/libraries/Driver.php */
+/* Location: ./system/libraries/Driver.php */
@@ -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'
@@ -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
*
@@ -158,13 +158,6 @@ class CI_Session_cookie extends CI_Session_driver {
public $userdata = array();
/**
- * Reference to CodeIgniter instance
- *
- * @var object
- */
- public $CI;
-
- /**
* Current time
*
* @var int
@@ -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(
@@ -46,7 +46,6 @@ protected function initialize()
{
// Get config parameters
$config = array();
- $CI =& get_instance();
$prefs = array(
'sess_cookie_name',
'sess_expire_on_close',
@@ -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
@@ -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;
@@ -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

0 comments on commit 2e3e230

Please sign in to comment.