Session_Cookie
Kohana_Session_Cookie
Session
Kohana_Session

Class Contents

Class declared in SYSPATH/classes/session/cookie.php on line 3.

Properties

public static $default
string(6) "native"

Methods

protected _destroy( )
Kohana_Session_Cookie

Source Code
protected function _destroy()
{
	return Cookie::delete($this->_name);
}

protected _read( )
Kohana_Session_Cookie

Source Code
protected function _read($id = NULL)
{
	return Cookie::get($this->_name, NULL);
}

protected _regenerate( )
Kohana_Session_Cookie

Source Code
protected function _regenerate()
{
	// Cookie sessions have no id
	return NULL;
}

protected _write( )
Kohana_Session_Cookie

Source Code
protected function _write()
{
	return Cookie::set($this->_name, $this->__toString(), $this->_lifetime);
}

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 id( )
Kohana_Session

Source Code
public function id()
{
	return NULL;
}

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 name( )
Kohana_Session

Source Code
public function name()
{
	return $this->_name;
}

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;
	}
}