Session_Native
› Kohana_Session_Native
› Session
› Kohana_Session
Class Contents
Constants
- None
Properties
Class declared in SYSPATH/classes/session/native.php on line 3.
Properties
- public static
$default string(6) "native"
Methods
protected _destroy( )
› Kohana_Session_Native
Source Code
protected function _destroy()
{
// Destroy the current session
session_destroy();
// Did destruction work?
$status = ! session_id();
if ($status)
{
// Make sure the session cannot be restarted
Cookie::delete($this->_name);
}
return $status;
}
protected _read( )
› Kohana_Session_Native
Source Code
protected function _read($id = NULL)
{
// Sync up the session cookie with Cookie parameters
session_set_cookie_params($this->_lifetime, Cookie::$path, Cookie::$domain, Cookie::$secure, Cookie::$httponly);
// Do not allow PHP to send Cache-Control headers
session_cache_limiter(FALSE);
// Set the session cookie name
session_name($this->_name);
if ($id)
{
// Set the session id
session_id($id);
}
// Start the session
session_start();
// Use the $_SESSION global for storing data
$this->_data =& $_SESSION;
return NULL;
}
protected _regenerate( )
› Kohana_Session_Native
Source Code
protected function _regenerate()
{
// Regenerate the session id
session_regenerate_id();
return session_id();
}
protected _write( )
› Kohana_Session_Native
Source Code
protected function _write()
{
// Write and close the session
session_write_close();
return TRUE;
}
public __construct( )
› Kohana_Session
Source Code
public function __construct(array $config = NULL, $id = NULL)
{
if (isset($config['name']))
{
// Cookie name to store the session id in
$this->_name = (string) $config['name'];
}
if (isset($config['lifetime']))
{
// Cookie lifetime
$this->_lifetime = (int) $config['lifetime'];
}
if (isset($config['encrypted']))
{
if ($config['encrypted'] === TRUE)
{
// Use the default Encrypt instance
$config['encrypted'] = 'default';
}
// Enable or disable encryption of data
$this->_encrypted = $config['encrypted'];
}
// Load the session
$this->read($id);
}
public __toString( )
› Kohana_Session
Source Code
public function __toString()
{
// Serialize the data array
$data = serialize($this->_data);
if ($this->_encrypted)
{
// Encrypt the data using the default key
$data = Encrypt::instance($this->_encrypted)->encode($data);
}
else
{
// Obfuscate the data with base64 encoding
$data = base64_encode($data);
}
return $data;
}
public as_array( )
› Kohana_Session
Source Code
public function & as_array()
{
return $this->_data;
}
public bind( )
› Kohana_Session
Source Code
public function bind($key, & $value)
{
$this->_data[$key] =& $value;
return $this;
}
public delete( )
› Kohana_Session
Source Code
public function delete($key)
{
$args = func_get_args();
foreach ($args as $key)
{
unset($this->_data[$key]);
}
return $this;
}
public destroy( )
› Kohana_Session
Source Code
public function destroy()
{
if ($this->_destroyed === FALSE)
{
if ($this->_destroyed = $this->_destroy())
{
// The session has been destroyed, clear all data
$this->_data = array();
}
}
return $this->_destroyed;
}
public get( )
› Kohana_Session
Source Code
public function get($key, $default = NULL)
{
return array_key_exists($key, $this->_data) ? $this->_data[$key] : $default;
}
public get_once( )
› Kohana_Session
Source Code
public function get_once($key, $default = NULL)
{
$value = $this->get($key, $default);
unset($this->_data[$key]);
return $value;
}
public static instance( )
› Kohana_Session
Source Code
public static function instance($type = NULL, $id = NULL)
{
if ($type === NULL)
{
// Use the default type
$type = Session::$default;
}
if ( ! isset(Session::$instances[$type]))
{
// Load the configuration for this type
$config = Kohana::config('session')->get($type);
// Set the session class name
$class = 'Session_'.ucfirst($type);
// Create a new session instance
Session::$instances[$type] = $session = new $class($config, $id);
// Write the session at shutdown
register_shutdown_function(array($session, 'write'));
}
return Session::$instances[$type];
}
public read( )
› Kohana_Session
Source Code
public function read($id = NULL)
{
if (is_string($data = $this->_read($id)))
{
try
{
if ($this->_encrypted)
{
// Decrypt the data using the default key
$data = Encrypt::instance($this->_encrypted)->decode($data);
}
else
{
// Decode the base64 encoded data
$data = base64_decode($data);
}
// Unserialize the data
$data = unserialize($data);
}
catch (Exception $e)
{
// Ignore all reading errors
}
}
if (is_array($data))
{
// Load the data locally
$this->_data = $data;
}
}
public regenerate( )
› Kohana_Session
Source Code
public function regenerate()
{
return $this->_regenerate();
}
public set( )
› Kohana_Session
Source Code
public function set($key, $value)
{
$this->_data[$key] = $value;
return $this;
}
public write( )
› Kohana_Session
Source Code
public function write()
{
if (headers_sent() OR $this->_destroyed)
{
// Session cannot be written when the headers are sent or when
// the session has been destroyed
return FALSE;
}
// Set the last active timestamp
$this->_data['last_active'] = time();
try
{
return $this->_write();
}
catch (Exception $e)
{
// Log & ignore all errors when a write fails
Kohana::$log->add(Kohana::ERROR, Kohana::exception_text($e))->write();
return FALSE;
}
}