Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Auth StorageInterface and classes
- Loading branch information
Showing
3 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |