Skip to content

Commit

Permalink
Add Auth StorageInterface and classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed May 28, 2015
1 parent a4f5190 commit f525de6
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Auth/Storage/NullStorage.php
@@ -0,0 +1,33 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.1.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Auth\Storage;

use Cake\Core\InstanceConfigTrait;
use Cake\Network\Request;

class NullStorage implements StorageInterface
{
public function get()
{
}

public function set(array $user)
{
}

public function remove()
{
}
}
57 changes: 57 additions & 0 deletions src/Auth/Storage/SessionStorage.php
@@ -0,0 +1,57 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.1.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Auth\Storage;

use Cake\Core\InstanceConfigTrait;
use Cake\Network\Request;

class SessionStorage implements StorageInterface
{

use InstanceConfigTrait;

protected $_session;

protected $_defaultConfig = [
'key' => 'Auth.User'
];

public function __construct(Request $request, array $config = [])
{
$this->_session = $request->session();
$this->config($config);
}

public function get()
{
if (!$this->_session->check($this->_config['key'])) {
return;
}

return $this->_session->read($this->_config['key']);
}

public function set(array $user)
{
$this->_session->renew();
$this->_session->write($this->_config['key'], $user);
}

public function remove()
{
$this->_session->delete($this->_config['key']);
$this->_session->renew();
}
}
24 changes: 24 additions & 0 deletions src/Auth/Storage/StorageInterface.php
@@ -0,0 +1,24 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.1.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Auth\Storage;

interface StorageInterface
{
public function get();

public function set(array $user);

public function remove();
}

0 comments on commit f525de6

Please sign in to comment.