Example #1
0
 /**
  * On first session instance creation, sets up the driver and creates session.
  */
 public function __construct()
 {
     $this->input = Input::instance();
     // This part only needs to be run once
     if (self::$instance === NULL) {
         // Load config
         self::$config = Kohana::config('session');
         // Makes a mirrored array, eg: foo=foo
         self::$protect = array_combine(self::$protect, self::$protect);
         // Configure garbage collection
         ini_set('session.gc_probability', (int) self::$config['gc_probability']);
         ini_set('session.gc_divisor', 100);
         ini_set('session.gc_maxlifetime', self::$config['expiration'] == 0 ? 86400 : self::$config['expiration']);
         // Create a new session
         $this->create();
         if (self::$config['regenerate'] > 0 and $_SESSION['total_hits'] % self::$config['regenerate'] === 0) {
             // Regenerate session id and update session cookie
             $this->regenerate();
         } else {
             // Always update session cookie to keep the session alive
             cookie::set(self::$config['name'], $_SESSION['session_id'], self::$config['expiration']);
         }
         // Close the session just before sending the headers, so that
         // the session cookie(s) can be written.
         Event::add('system.send_headers', array($this, 'write_close'));
         // Make sure that sessions are closed before exiting
         register_shutdown_function(array($this, 'write_close'));
         // Singleton instance
         self::$instance = $this;
     }
     Kohana::log('debug', 'Session Library initialized');
 }
Example #2
0
 /**
  * Constructor: __construct
  *  On first session instance creation, sets up the driver and creates session.
  */
 public function __construct()
 {
     $this->input = new Input();
     // This part only needs to be run once
     if (self::$instance === NULL) {
         // Load config
         self::$config = Eight::config('session');
         // Makes a mirrored array, eg: foo=foo
         self::$protect = array_combine(self::$protect, self::$protect);
         if (self::$config['driver'] != 'native') {
             // Set driver name
             $driver = 'Session_Driver_' . ucfirst(self::$config['driver']);
             // Load the driver
             if (!Eight::auto_load($driver)) {
                 throw new Eight_Exception('session.driver_not_supported', self::$config['driver']);
             }
             // Initialize the driver
             self::$driver = new $driver();
             // Validate the driver
             if (!self::$driver instanceof Session_Driver) {
                 throw new Eight_Exception('session.driver_must_implement_interface');
             }
         }
         // Create a new session
         $this->create();
         // Regenerate session id
         if (self::$config['regenerate'] > 0 and $_SESSION['total_hits'] % self::$config['regenerate'] === 0) {
             $this->regenerate();
         }
         // Close the session just before sending the headers, so that
         // the session cookie can be written
         Event::add('system.post_controller', 'session_write_close');
         // Singleton instance
         self::$instance = $this;
     }
     Eight::log('debug', 'Session Library initialized');
 }