1: <?php namespace Laravel\Session\Drivers;
2:
3: use Laravel\Config;
4: use Laravel\Database\Connection;
5:
6: class Database extends Driver implements Sweeper {
7:
8: 9: 10: 11: 12:
13: protected $connection;
14:
15: 16: 17: 18: 19: 20:
21: public function __construct(Connection $connection)
22: {
23: $this->connection = $connection;
24: }
25:
26: 27: 28: 29: 30: 31: 32: 33:
34: public function load($id)
35: {
36: $session = $this->table()->find($id);
37:
38: if ( ! is_null($session))
39: {
40: return array(
41: 'id' => $session->id,
42: 'last_activity' => $session->last_activity,
43: 'data' => unserialize($session->data)
44: );
45: }
46: }
47:
48: 49: 50: 51: 52: 53: 54: 55:
56: public function save($session, $config, $exists)
57: {
58: if ($exists)
59: {
60: $this->table()->where('id', '=', $session['id'])->update(array(
61: 'last_activity' => $session['last_activity'],
62: 'data' => serialize($session['data']),
63: ));
64: }
65: else
66: {
67: $this->table()->insert(array(
68: 'id' => $session['id'],
69: 'last_activity' => $session['last_activity'],
70: 'data' => serialize($session['data'])
71: ));
72: }
73: }
74:
75: 76: 77: 78: 79: 80:
81: public function delete($id)
82: {
83: $this->table()->delete($id);
84: }
85:
86: 87: 88: 89: 90: 91:
92: public function sweep($expiration)
93: {
94: $this->table()->where('last_activity', '<', $expiration)->delete();
95: }
96:
97: 98: 99: 100: 101:
102: private function table()
103: {
104: return $this->connection->table(Config::get('session.table'));
105: }
106:
107: }