first commit of 2.0
This commit is contained in:
41
laravel/session/apc.php
Normal file
41
laravel/session/apc.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php namespace Laravel\Session;
|
||||
|
||||
use Laravel\Cache;
|
||||
use Laravel\Config;
|
||||
|
||||
class APC implements Driver {
|
||||
|
||||
/**
|
||||
* Load a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return array
|
||||
*/
|
||||
public function load($id)
|
||||
{
|
||||
return Cache::driver('apc')->get($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a session.
|
||||
*
|
||||
* @param array $session
|
||||
* @return void
|
||||
*/
|
||||
public function save($session)
|
||||
{
|
||||
Cache::driver('apc')->put($session['id'], $session, Config::get('session.lifetime'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
Cache::driver('apc')->forget($id);
|
||||
}
|
||||
|
||||
}
|
||||
73
laravel/session/cookie.php
Normal file
73
laravel/session/cookie.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php namespace Laravel\Session;
|
||||
|
||||
use Laravel\Config;
|
||||
use Laravel\Crypter;
|
||||
|
||||
class Cookie implements Driver {
|
||||
|
||||
/**
|
||||
* The Crypter instance.
|
||||
*
|
||||
* @var Crypter
|
||||
*/
|
||||
private $crypter;
|
||||
|
||||
/**
|
||||
* Create a new Cookie session driver instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->crypter = new Crypter;
|
||||
|
||||
if (Config::get('application.key') == '')
|
||||
{
|
||||
throw new \Exception("You must set an application key before using the Cookie session driver.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return array
|
||||
*/
|
||||
public function load($id)
|
||||
{
|
||||
if (\System\Cookie::has('session_payload'))
|
||||
{
|
||||
return unserialize($this->crypter->decrypt(\System\Cookie::get('session_payload')));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a session.
|
||||
*
|
||||
* @param array $session
|
||||
* @return void
|
||||
*/
|
||||
public function save($session)
|
||||
{
|
||||
if ( ! headers_sent())
|
||||
{
|
||||
extract(Config::get('session'));
|
||||
|
||||
$payload = $this->crypter->encrypt(serialize($session));
|
||||
|
||||
\System\Cookie::put('session_payload', $payload, $lifetime, $path, $domain, $https, $http_only);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
\System\Cookie::forget('session_payload');
|
||||
}
|
||||
|
||||
}
|
||||
76
laravel/session/db.php
Normal file
76
laravel/session/db.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php namespace Laravel\Session;
|
||||
|
||||
use Laravel\Config;
|
||||
|
||||
class DB implements Driver, Sweeper {
|
||||
|
||||
/**
|
||||
* Load a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return array
|
||||
*/
|
||||
public function load($id)
|
||||
{
|
||||
$session = $this->table()->find($id);
|
||||
|
||||
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)
|
||||
{
|
||||
$this->delete($session['id']);
|
||||
|
||||
$this->table()->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->table()->delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all expired sessions.
|
||||
*
|
||||
* @param int $expiration
|
||||
* @return void
|
||||
*/
|
||||
public function sweep($expiration)
|
||||
{
|
||||
$this->table()->where('last_activity', '<', $expiration)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a session database query.
|
||||
*
|
||||
* @return Query
|
||||
*/
|
||||
private function table()
|
||||
{
|
||||
return \System\DB::connection()->table(Config::get('session.table'));
|
||||
}
|
||||
|
||||
}
|
||||
29
laravel/session/driver.php
Normal file
29
laravel/session/driver.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php namespace Laravel\Session;
|
||||
|
||||
interface Driver {
|
||||
|
||||
/**
|
||||
* Load a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return array
|
||||
*/
|
||||
public function load($id);
|
||||
|
||||
/**
|
||||
* Save a session.
|
||||
*
|
||||
* @param array $session
|
||||
* @return void
|
||||
*/
|
||||
public function save($session);
|
||||
|
||||
/**
|
||||
* Delete a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function delete($id);
|
||||
|
||||
}
|
||||
52
laravel/session/file.php
Normal file
52
laravel/session/file.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php namespace Laravel\Session;
|
||||
|
||||
class File implements Driver, Sweeper {
|
||||
|
||||
/**
|
||||
* Load a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return array
|
||||
*/
|
||||
public function load($id)
|
||||
{
|
||||
if (file_exists($path = SESSION_PATH.$id)) return unserialize(file_get_contents($path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a session.
|
||||
*
|
||||
* @param array $session
|
||||
* @return void
|
||||
*/
|
||||
public function save($session)
|
||||
{
|
||||
file_put_contents(SESSION_PATH.$session['id'], serialize($session), LOCK_EX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
@unlink(SESSION_PATH.$id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all expired sessions.
|
||||
*
|
||||
* @param int $expiration
|
||||
* @return void
|
||||
*/
|
||||
public function sweep($expiration)
|
||||
{
|
||||
foreach (glob(SESSION_PATH.'*') as $file)
|
||||
{
|
||||
if (filetype($file) == 'file' and filemtime($file) < $expiration) @unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
41
laravel/session/memcached.php
Normal file
41
laravel/session/memcached.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php namespace Laravel\Session;
|
||||
|
||||
use Laravel\Cache;
|
||||
use Laravel\Config;
|
||||
|
||||
class Memcached implements Driver {
|
||||
|
||||
/**
|
||||
* Load a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return array
|
||||
*/
|
||||
public function load($id)
|
||||
{
|
||||
return Cache::driver('memcached')->get($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a session.
|
||||
*
|
||||
* @param array $session
|
||||
* @return void
|
||||
*/
|
||||
public function save($session)
|
||||
{
|
||||
Cache::driver('memcached')->put($session['id'], $session, Config::get('session.lifetime'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a session by ID.
|
||||
*
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
Cache::driver('memcached')->forget($id);
|
||||
}
|
||||
|
||||
}
|
||||
13
laravel/session/sweeper.php
Normal file
13
laravel/session/sweeper.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php namespace Laravel\Session;
|
||||
|
||||
interface Sweeper {
|
||||
|
||||
/**
|
||||
* Delete all expired sessions.
|
||||
*
|
||||
* @param int $expiration
|
||||
* @return void
|
||||
*/
|
||||
public function sweep($expiration);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user