Changeset 1637

Show
Ignore:
Timestamp:
12/28/2007 12:41:16 PM (11 months ago)
Author:
Shadowhand
Message:

Added Session::instance().

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/Session.php

    r1619 r1637  
    1010class Session_Core { 
    1111 
    12         // Number of instances of Session object 
    13         private static $instances = 0; 
     12        // Session singleton 
     13        private static $instance; 
    1414 
    1515        // Protected key names (cannot be set by the user) 
     
    2727 
    2828        /** 
     29         * Singleton instance of Session. 
     30         */ 
     31        public static function instance() 
     32        { 
     33                // Create the instance if it does not exist 
     34                empty(self::$instance) and new Session; 
     35 
     36                return self::$instance; 
     37        } 
     38 
     39        /** 
    2940         * Constructor: __construct 
    3041         *  On first session instance creation, sets up the driver and creates session. 
     
    3546 
    3647                // This part only needs to be run once 
    37                 if (self::$instances === 0) 
     48                if (self::$instance === NULL) 
    3849                { 
    3950                        // Load config 
     
    7889                        // the session cookie can be written 
    7990                        Event::add('system.send_headers', 'session_write_close'); 
    80                 } 
    81  
    82                 // New instance 
    83                 self::$instances += 1; 
     91 
     92                        // Singleton instance 
     93                        self::$instance = $this; 
     94                } 
    8495 
    8596                Log::add('debug', 'Session Library initialized'); 
     
    133144                if ( ! isset($_SESSION['_kf_flash_'])) 
    134145                { 
    135                         $_SESSION['user_agent'] = $this->input->user_agent(); 
     146                        $_SESSION['user_agent'] = Kohana::$user_agent; 
    136147                        $_SESSION['ip_address'] = $this->input->ip_address(); 
    137148                        $_SESSION['_kf_flash_'] = array();