refactoring session for better architecture.

This commit is contained in:
Taylor Otwell
2011-09-15 20:23:30 -05:00
parent a97c45e034
commit 5a9696da77
14 changed files with 446 additions and 385 deletions

View File

@@ -2,14 +2,14 @@
use Laravel\Database\Connection;
class Database extends Driver implements Sweeper {
class Database implements Driver, Sweeper {
/**
* The database connection.
*
* @var Connection
*/
protected $connection;
private $connection;
/**
* Create a new database session driver.
@@ -23,16 +23,14 @@ class Database extends Driver implements Sweeper {
}
/**
* Load a session by ID.
* Load a session from storage by a given ID.
*
* This method is responsible for retrieving the session from persistant storage. If the
* session does not exist in storage, nothing should be returned from the method, in which
* case a new session will be created by the base driver.
* If no session is found for the ID, null will be returned.
*
* @param string $id
* @return array
*/
protected function load($id)
public function load($id)
{
$session = $this->table()->find($id);
@@ -47,12 +45,13 @@ class Database extends Driver implements Sweeper {
}
/**
* Save the session to persistant storage.
* Save a given session to storage.
*
* @param array $session
* @param array $config
* @return void
*/
protected function save($session)
public function save($session, $config)
{
$this->delete($session['id']);
@@ -64,12 +63,12 @@ class Database extends Driver implements Sweeper {
}
/**
* Delete the session from persistant storage.
* Delete a session from storage by a given ID.
*
* @param string $id
* @return void
*/
protected function delete($id)
public function delete($id)
{
$this->table()->delete($id);
}
@@ -90,7 +89,7 @@ class Database extends Driver implements Sweeper {
*
* @return Query
*/
protected function table()
private function table()
{
return $this->connection->table($this->config->get('session.table'));
}