1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php namespace System\Session;
- use System\Config;
- class DB implements Driver {
- /**
- * Load a session by ID.
- *
- * @param string $id
- * @return array
- */
- public function load($id)
- {
- $session = $this->table()->find($id);
- if ( ! is_null($session))
- {
- return array('id' => $session->id, 'last_activity' => $session->last_activity, 'data' => unserialize($session->data));
- }
- }
- /**
- * Save a session.
- *
- * @param array $session
- * @return void
- */
- public function save($session)
- {
- $this->delete($session['id']);
- $this->table()->insert(array('id' => $session['id'], 'last_activity' => $session['last_activity'], 'data' => serialize($session['data'])));
- }
- /**
- * Delete a session by ID.
- *
- * @param string $id
- * @return void
- */
- public function delete($id)
- {
- $this->table()->delete($id);
- }
- /**
- * Delete all expired sessions.
- *
- * @param int $expiration
- * @return void
- */
- public function sweep($expiration)
- {
- $this->table()->where('last_activity', '<', $expiration)->delete();
- }
- /**
- * Get a session database query.
- *
- * @return Query
- */
- private function table()
- {
- return \System\DB::table(Config::get('session.table'));
- }
-
- }
|