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,7 +2,7 @@
use Laravel\Security\Crypter;
class Cookie extends Driver {
class Cookie implements Driver {
/**
* The cookie manager instance.
@@ -36,16 +36,14 @@ class Cookie extends Driver {
}
/**
* 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)
{
if ($this->cookie->has('session_payload'))
{
@@ -54,17 +52,16 @@ class Cookie extends Driver {
}
/**
* 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)
{
if ( ! headers_sent())
{
$config = $this->config->get('session');
extract($config);
$payload = $this->crypter->encrypt(serialize($session));
@@ -74,12 +71,12 @@ class Cookie extends Driver {
}
/**
* 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->cookie->forget('session_payload');
}