Edited session class to use new Cookie send method.
This commit is contained in:
parent
3cffaf589d
commit
afd0026015
|
@ -17,15 +17,13 @@ class Session {
|
||||||
private static $session = array();
|
private static $session = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the session driver instance.
|
* Get the session driver. If the driver has already been instantiated, that
|
||||||
|
* instance will be returned.
|
||||||
*
|
*
|
||||||
* @return Session\Driver
|
* @return Session\Driver
|
||||||
*/
|
*/
|
||||||
public static function driver()
|
public static function driver()
|
||||||
{
|
{
|
||||||
// -----------------------------------------------------
|
|
||||||
// Create the session driver if we haven't already.
|
|
||||||
// -----------------------------------------------------
|
|
||||||
if (is_null(static::$driver))
|
if (is_null(static::$driver))
|
||||||
{
|
{
|
||||||
static::$driver = Session\Factory::make(Config::get('session.driver'));
|
static::$driver = Session\Factory::make(Config::get('session.driver'));
|
||||||
|
@ -59,7 +57,7 @@ public static function load()
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
// Generate a CSRF token if one does not exist.
|
// Create a CSRF token for the session if necessary.
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
if ( ! static::has('csrf_token'))
|
if ( ! static::has('csrf_token'))
|
||||||
{
|
{
|
||||||
|
@ -70,7 +68,7 @@ public static function load()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the session contains an item.
|
* Determine if the session or flash data contains an item.
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return bool
|
* @return bool
|
||||||
|
@ -83,7 +81,7 @@ public static function has($key)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an item from the session.
|
* Get an item from the session or flash data.
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
@ -96,9 +94,6 @@ public static function get($key, $default = null)
|
||||||
{
|
{
|
||||||
return static::$session['data'][$key];
|
return static::$session['data'][$key];
|
||||||
}
|
}
|
||||||
// -----------------------------------------------------
|
|
||||||
// Check the flash data for the item.
|
|
||||||
// -----------------------------------------------------
|
|
||||||
elseif (array_key_exists(':old:'.$key, static::$session['data']))
|
elseif (array_key_exists(':old:'.$key, static::$session['data']))
|
||||||
{
|
{
|
||||||
return static::$session['data'][':old:'.$key];
|
return static::$session['data'][':old:'.$key];
|
||||||
|
@ -125,7 +120,7 @@ public static function put($key, $value)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a flash item to the session.
|
* Write an item to the session flash data.
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
|
@ -176,17 +171,14 @@ public static function regenerate()
|
||||||
public static function close()
|
public static function close()
|
||||||
{
|
{
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
// Flash the old input data to the session.
|
// Flash the old input to the session and age the flash.
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
static::flash('laravel_old_input', Input::get());
|
static::flash('laravel_old_input', Input::get());
|
||||||
|
|
||||||
// -----------------------------------------------------
|
|
||||||
// Age the flash data.
|
|
||||||
// -----------------------------------------------------
|
|
||||||
static::age_flash();
|
static::age_flash();
|
||||||
|
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
// Save the session data to storage.
|
// Write the session data to storage.
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
static::driver()->save(static::$session);
|
static::driver()->save(static::$session);
|
||||||
|
|
||||||
|
@ -195,8 +187,18 @@ public static function close()
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
if ( ! headers_sent())
|
if ( ! headers_sent())
|
||||||
{
|
{
|
||||||
$lifetime = (Config::get('session.expire_on_close')) ? 0 : Config::get('session.lifetime');
|
$cookie = new Cookie('laravel_session', static::$session['id']);
|
||||||
Cookie::put('laravel_session', static::$session['id'], $lifetime, Config::get('session.path'), Config::get('session.domain'), Config::get('session.https'));
|
|
||||||
|
if ( ! Config::get('session.expire_on_close'))
|
||||||
|
{
|
||||||
|
$cookie->lifetime = Config::get('session.lifetime');
|
||||||
|
}
|
||||||
|
|
||||||
|
$cookie->path = Config::get('session.path');
|
||||||
|
$cookie->domain = Config::get('session.domain');
|
||||||
|
$cookie->secure = Config::get('session.https');
|
||||||
|
|
||||||
|
$cookie->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
|
@ -204,7 +206,7 @@ public static function close()
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
if (mt_rand(1, 100) <= 2)
|
if (mt_rand(1, 100) <= 2)
|
||||||
{
|
{
|
||||||
static::driver()->sweep(time() - (Config::get('session.lifetime') * 60));
|
static::driver()->sweep(time() - ($config['lifetime'] * 60));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,12 +236,12 @@ private static function age_flash()
|
||||||
if (strpos($key, ':new:') === 0)
|
if (strpos($key, ':new:') === 0)
|
||||||
{
|
{
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
// Create an :old: flash item.
|
// Create an :old: item for the :new: item.
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
static::put(':old:'.substr($key, 5), $value);
|
static::put(':old:'.substr($key, 5), $value);
|
||||||
|
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
// Forget the :new: flash item.
|
// Forget the :new: item.
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
static::forget($key);
|
static::forget($key);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue