123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php namespace Laravel;
- if (Config::get('application.key') === '')
- {
- throw new \Exception("An application key is required to use sessions.");
- }
- class Session {
-
- public static $instance;
-
- const csrf_token = 'csrf_token';
-
- public static function start($driver)
- {
- static::$instance = new Session\Payload(static::factory($driver));
- }
-
- protected static function factory($driver)
- {
- switch ($driver)
- {
- case 'apc':
- return new Session\Drivers\APC(Cache::driver('apc'));
- case 'cookie':
- return new Session\Drivers\Cookie;
- case 'database':
- return new Session\Drivers\Database(Database::connection());
- case 'file':
- return new Session\Drivers\File(SESSION_PATH);
- case 'memcached':
- return new Session\Drivers\Memcached(Cache::driver('memcached'));
- case 'redis':
- return new Session\Drivers\Redis(Cache::driver('redis'));
- default:
- throw new \Exception("Session driver [$driver] is not supported.");
- }
- }
-
- public static function instance()
- {
- if (static::started()) return static::$instance;
- throw new \Exception("A driver must be set before using the session.");
- }
-
- public static function started()
- {
- return ! is_null(static::$instance);
- }
-
- public static function __callStatic($method, $parameters)
- {
- return call_user_func_array(array(static::instance(), $method), $parameters);
- }
- }
|