mako\session\Database


Description


Redis adapter.


Class methods


Toggle source

public __construct($config)


Constructor.


Parameters

Type Description
array Configuration
Return value

NULL

public function __construct(array $config)
{
	parent::__construct();

	$this->connection = DB::connection($config['configuration']);

	$this->table = $config['table'];
}

Toggle source

public __destruct()


Destructor.

Return value

NULL

public function __destruct()
{
	session_write_close();

	// Fixes issue with Debian and Ubuntu session garbage collection

	if(mt_rand(1, 100) === 100)
	{
		$this->gc(0);
	}
}

Toggle source

protected table()


Returns a query builder instance.

Return value

mako\database\Query

protected function table()
{
	return $this->connection->table($this->table);
}

Toggle source

public read($id)


Returns session data.


Parameters

Type Description
string Session id
Return value

string

public function read($id)
{
	try
	{
		$data = $this->table()->where('id', '=', $id)->column('data');

		return ($data !== false) ? $data : '';
	}
	catch(PDOException $e)
	{
		return '';
	}
}

Toggle source

public write($id, $data)


Writes data to the session.


Parameters

Type Description
string Session id
string Session data
Return value

NULL

public function write($id, $data)
{
	try
	{
		if($this->table()->where('id', '=', $id)->count() != 0)
		{
			return (bool) $this->table()->where('id', '=', $id)->update(array('data' => $data, 'expires' => (time() + $this->maxLifetime)));
		}
		else
		{
			return $this->table()->insert(array('id' => $id, 'data' => $data, 'expires' => (time() + $this->maxLifetime)));
		}
	}
	catch(PDOException $e)
	{
		return false;
	}
}

Toggle source

public destroy($id)


Destroys the session.


Parameters

Type Description
string Session id
Return value

boolean

public function destroy($id)
{
	try
	{
		return (bool) $this->table()->where('id', '=', $id)->delete();
	}
	catch(PDOException $e)
	{
		return false;
	}
}

Toggle source

public gc($maxLifetime)


Garbage collector.


Parameters

Type Description
int Lifetime in secods
Return value

boolean

public function gc($maxLifetime)
{
	try
	{
		return (bool) $this->table()->where('expires', '<', time())->delete();
	}
	catch(PDOException $e)
	{
		return false;
	}
}

Toggle source

public open($savePath, $sessionName)


Session "constructor".


Parameters

Type Description
string Save path
string Session name
Return value

boolean


public function __destruct()
{
	session_write_close();

	// Fixes issue with Debian and Ubuntu session garbage collection

Toggle source

public close()


Session "destructor".

Return value

boolean

// Class methods
//---------------------------------------------

/**