Commit a3e8d5ae authored by Taylor Otwell's avatar Taylor Otwell

Refactoring the session class.

parent 6f26ce6e
...@@ -46,6 +46,8 @@ class Session { ...@@ -46,6 +46,8 @@ class Session {
throw new \Exception("Session driver [$driver] is not supported."); throw new \Exception("Session driver [$driver] is not supported.");
} }
} }
return static::$driver;
} }
/** /**
...@@ -63,10 +65,7 @@ class Session { ...@@ -63,10 +65,7 @@ class Session {
static::$session = array('id' => Str::random(40), 'data' => array()); static::$session = array('id' => Str::random(40), 'data' => array());
} }
if ( ! static::has('csrf_token')) if ( ! static::has('csrf_token')) static::put('csrf_token', Str::random(16));
{
static::put('csrf_token', Str::random(16));
}
static::$session['last_activity'] = time(); static::$session['last_activity'] = time();
} }
...@@ -191,19 +190,11 @@ class Session { ...@@ -191,19 +190,11 @@ class Session {
static::driver()->save(static::$session); static::driver()->save(static::$session);
$config = Config::get('session'); static::write_cookie();
if ( ! headers_sent())
{
$minutes = ($config['expire_on_close']) ? 0 : $config['lifetime'];
Cookie::put('laravel_session', static::$session['id'], $minutes, $config['path'], $config['domain'], $config['https'], $config['http_only']);
}
// 2% chance of performing session garbage collection on any given request...
if (mt_rand(1, 100) <= 2 and static::driver() instanceof Session\Sweeper) if (mt_rand(1, 100) <= 2 and static::driver() instanceof Session\Sweeper)
{ {
static::driver()->sweep(time() - ($config['lifetime'] * 60)); static::driver()->sweep(time() - (Config::get('session.lifetime') * 60));
} }
} }
...@@ -233,4 +224,21 @@ class Session { ...@@ -233,4 +224,21 @@ class Session {
} }
} }
/**
* Write the session cookie.
*
* @return void
*/
private static function write_cookie()
{
extract(Config::get('session'));
if ( ! headers_sent())
{
$minutes = ($expire_on_close) ? 0 : $lifetime;
Cookie::put('laravel_session', static::$session['id'], $minutes, $path, $domain, $https, $http_only);
}
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment