12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php namespace System\Session;
- use System\Config;
- class DB implements Driver, Sweeper {
- /**
- * 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::connection()->table(Config::get('session.table'));
- }
-
- }
|