From 32f383205e00c99b47e2812ead78fd37eb94360c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 2 Aug 2011 21:05:20 -0500 Subject: [PATCH] restructured session driver interfaces and added cookie session driver. --- application/config/session.php | 2 +- system/session.php | 8 +++-- system/session/apc.php | 11 ------- system/session/cookie.php | 54 ++++++++++++++++++++++++++++++++++ system/session/db.php | 2 +- system/session/driver.php | 8 ----- system/session/file.php | 2 +- system/session/memcached.php | 11 ------- system/session/sweeper.php | 13 ++++++++ 9 files changed, 76 insertions(+), 35 deletions(-) create mode 100644 system/session/cookie.php create mode 100644 system/session/sweeper.php diff --git a/application/config/session.php b/application/config/session.php index 2da93353..12ccb6ff 100644 --- a/application/config/session.php +++ b/application/config/session.php @@ -12,7 +12,7 @@ | Since HTTP is stateless, sessions are used to maintain "state" across | multiple requests from the same user of your application. | - | Supported Drivers: 'file', 'db', 'memcached', 'apc'. + | Supported Drivers: 'cookie', 'file', 'db', 'memcached', 'apc'. | */ diff --git a/system/session.php b/system/session.php index 63000e35..c57d6d97 100644 --- a/system/session.php +++ b/system/session.php @@ -27,6 +27,10 @@ public static function driver() { switch (Config::get('session.driver')) { + case 'cookie': + static::$driver = new Session\Cookie; + break; + case 'file': static::$driver = new Session\File; break; @@ -203,8 +207,8 @@ public static function close() Cookie::put('laravel_session', static::$session['id'], $minutes, $config['path'], $config['domain'], $config['https'], $config['http_only']); } - // 2% chance of performing session garbage collection... - if (mt_rand(1, 100) <= 2) + // 2% chance of performing session garbage collection on any given request... + if (mt_rand(1, 100) <= 2 and static::driver() instanceof Session\Sweeper) { static::driver()->sweep(time() - ($config['lifetime'] * 60)); } diff --git a/system/session/apc.php b/system/session/apc.php index 3716b5e4..7b236ba9 100644 --- a/system/session/apc.php +++ b/system/session/apc.php @@ -37,15 +37,4 @@ public function delete($id) Cache::driver('apc')->forget($id); } - /** - * Delete all expired sessions. - * - * @param int $expiration - * @return void - */ - public function sweep($expiration) - { - // APC sessions will expire automatically. - } - } \ No newline at end of file diff --git a/system/session/cookie.php b/system/session/cookie.php new file mode 100644 index 00000000..477b1f1f --- /dev/null +++ b/system/session/cookie.php @@ -0,0 +1,54 @@ +forget($id); } - /** - * Delete all expired sessions. - * - * @param int $expiration - * @return void - */ - public function sweep($expiration) - { - // Memcached sessions will expire automatically. - } - } \ No newline at end of file diff --git a/system/session/sweeper.php b/system/session/sweeper.php new file mode 100644 index 00000000..187ac414 --- /dev/null +++ b/system/session/sweeper.php @@ -0,0 +1,13 @@ +