initial commit of laravel!
This commit is contained in:
78
system/session/driver/db.php
Normal file
78
system/session/driver/db.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php namespace System\Session\Driver;
|
||||
|
||||
class DB implements \System\Session\Driver {
|
||||
|
||||
/**
|
||||
* Load a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return array
|
||||
*/
|
||||
public function load($id)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Find the session in the database.
|
||||
// -----------------------------------------------------
|
||||
$session = $this->query()->find($id);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// If the session was found, return it.
|
||||
// -----------------------------------------------------
|
||||
if ( ! is_null($session))
|
||||
{
|
||||
return array('id' => $session->id, 'last_activity' => $session->last_activity, 'data' => unserialize($session->data));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a session.
|
||||
*
|
||||
* @param array $session
|
||||
* @return void
|
||||
*/
|
||||
public function save($session)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Delete the existing session row.
|
||||
// -----------------------------------------------------
|
||||
$this->delete($session['id']);
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Insert a new session row.
|
||||
// -----------------------------------------------------
|
||||
$this->query()->insert(array('id' => $session['id'], 'last_activity' => $session['last_activity'], 'data' => serialize($session['data'])));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$this->query()->where('id', '=', $id)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all expired sessions.
|
||||
*
|
||||
* @param int $expiration
|
||||
* @return void
|
||||
*/
|
||||
public function sweep($expiration)
|
||||
{
|
||||
$this->query()->where('last_activity', '<', $expiration)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a session database query.
|
||||
*
|
||||
* @return Query
|
||||
*/
|
||||
private function query()
|
||||
{
|
||||
return \System\DB::table(\System\Config::get('session.table'));
|
||||
}
|
||||
|
||||
}
|
||||
64
system/session/driver/file.php
Normal file
64
system/session/driver/file.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php namespace System\Session\Driver;
|
||||
|
||||
class File implements \System\Session\Driver {
|
||||
|
||||
/**
|
||||
* Load a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return array
|
||||
*/
|
||||
public function load($id)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// Look for the session on the file system.
|
||||
// -----------------------------------------------------
|
||||
if (file_exists($path = APP_PATH.'sessions/'.$id))
|
||||
{
|
||||
return unserialize(file_get_contents($path));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a session.
|
||||
*
|
||||
* @param array $session
|
||||
* @return void
|
||||
*/
|
||||
public function save($session)
|
||||
{
|
||||
file_put_contents(APP_PATH.'sessions/'.$session['id'], serialize($session), LOCK_EX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
@unlink(APP_PATH.'sessions/'.$id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all expired sessions.
|
||||
*
|
||||
* @param int $expiration
|
||||
* @return void
|
||||
*/
|
||||
public function sweep($expiration)
|
||||
{
|
||||
foreach (glob(APP_PATH.'sessions/*') as $file)
|
||||
{
|
||||
// -----------------------------------------------------
|
||||
// If the session file has expired, delete it.
|
||||
// -----------------------------------------------------
|
||||
if (filetype($file) == 'file' and filemtime($file) < $expiration)
|
||||
{
|
||||
@unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
49
system/session/driver/memcached.php
Normal file
49
system/session/driver/memcached.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php namespace System\Session\Driver;
|
||||
|
||||
class Memcached implements \System\Session\Driver {
|
||||
|
||||
/**
|
||||
* Load a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return array
|
||||
*/
|
||||
public function load($id)
|
||||
{
|
||||
return \System\Cache::driver('memcached')->get($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a session.
|
||||
*
|
||||
* @param array $session
|
||||
* @return void
|
||||
*/
|
||||
public function save($session)
|
||||
{
|
||||
\System\Cache::driver('memcached')->put($session['id'], $session, \System\Config::get('session.lifetime'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
\System\Cache::driver('memcached')->forget($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all expired sessions.
|
||||
*
|
||||
* @param int $expiration
|
||||
* @return void
|
||||
*/
|
||||
public function sweep($expiration)
|
||||
{
|
||||
// Memcached sessions will expire automatically.
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user