Redis adapter.
Constructor.
| Type | Description |
|---|---|
| array | Configuration |
NULL
public function __construct(array $config)
{
parent::__construct();
$this->connection = DB::connection($config['configuration']);
$this->table = $config['table'];
}
Destructor.
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);
}
}
Returns a query builder instance.
mako\database\Query
protected function table()
{
return $this->connection->table($this->table);
}
Returns session data.
| Type | Description |
|---|---|
| string | Session id |
string
public function read($id)
{
try
{
$data = $this->table()->where('id', '=', $id)->column('data');
return ($data !== false) ? $data : '';
}
catch(PDOException $e)
{
return '';
}
}
Writes data to the session.
| Type | Description |
|---|---|
| string | Session id |
| string | Session data |
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;
}
}
Destroys the session.
| Type | Description |
|---|---|
| string | Session id |
boolean
public function destroy($id)
{
try
{
return (bool) $this->table()->where('id', '=', $id)->delete();
}
catch(PDOException $e)
{
return false;
}
}
Garbage collector.
| Type | Description |
|---|---|
| int | Lifetime in secods |
boolean
public function gc($maxLifetime)
{
try
{
return (bool) $this->table()->where('expires', '<', time())->delete();
}
catch(PDOException $e)
{
return false;
}
}
Session "constructor".
| Type | Description |
|---|---|
| string | Save path |
| string | Session name |
boolean
public function __destruct()
{
session_write_close();
// Fixes issue with Debian and Ubuntu session garbage collection
Session "destructor".
boolean
// Class methods //--------------------------------------------- /**