Skip to content

Commit

Permalink
Improve code to avoid accessing session
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed May 29, 2015
1 parent ef8a0dd commit 65c8ce3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/Auth/Storage/SessionStorage.php
Expand Up @@ -28,7 +28,10 @@ class SessionStorage implements StorageInterface
/**
* User record.
*
* @var array
* Stores user record array if fetched from session or false if session
* does not have user record.
*
* @var array|bool
*/
protected $_user;

Expand All @@ -40,7 +43,7 @@ class SessionStorage implements StorageInterface
protected $_session;

/**
* Default configuration for this class
* Default configuration for this class.
*
* @var array
*/
Expand All @@ -67,11 +70,11 @@ public function __construct(Request $request, array $config = [])
*/
public function get()
{
if ($this->_user) {
return $this->_user;
if ($this->_user !== null) {
return $this->_user ?: null;
}

$this->_user = $this->_session->read($this->_config['key']);
$this->_user = $this->_session->read($this->_config['key']) ?: false;
return $this->_user;
}

Expand Down Expand Up @@ -100,7 +103,7 @@ public function set(array $user)
*/
public function remove()
{
$this->_user = null;
$this->_user = false;

$this->_session->delete($this->_config['key']);
$this->_session->renew();
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Controller/Component/AuthComponentTest.php
Expand Up @@ -183,7 +183,7 @@ public function testRedirectVarClearing()
$this->Auth->startup($event);
$this->assertEquals('/auth_test/add', $this->Auth->session->read('Auth.redirect'));

$this->Auth->session->write('Auth.User', ['username' => 'admad']);
$this->Auth->storage()->set(['username' => 'admad']);
$this->Auth->startup($event, $this->Controller);
$this->assertNull($this->Auth->session->read('Auth.redirect'));
}
Expand Down

0 comments on commit 65c8ce3

Please sign in to comment.